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

DomCR / ACadSharp / 11434851786

21 Oct 2024 06:59AM UTC coverage: 76.287% (+0.001%) from 76.286%
11434851786

push

github

web-flow
Merge pull request #476 from DomCR/viewport-scale

Viewport scale

4931 of 7161 branches covered (68.86%)

Branch coverage included in aggregate %.

79 of 115 new or added lines in 9 files covered. (68.7%)

1 existing line in 1 file now uncovered.

19763 of 25209 relevant lines covered (78.4%)

36354.61 hits per line

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

85.18
/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
1
using ACadSharp.Blocks;
2
using ACadSharp.Classes;
3
using ACadSharp.Entities;
4
using ACadSharp.Types.Units;
5
using ACadSharp.IO.Templates;
6
using ACadSharp.Objects;
7
using ACadSharp.Tables;
8
using ACadSharp.Tables.Collections;
9
using CSMath;
10
using System.Collections.Generic;
11
using System.Linq;
12
using System.IO;
13
using System;
14
using CSUtilities.Converters;
15
using CSUtilities.Extensions;
16
using static ACadSharp.Objects.MultiLeaderAnnotContext;
17

18
namespace ACadSharp.IO.DWG
19
{
20
        /* Documentation:
21
         * This region holds the actual objects in the drawing.
22
         * These can be entities, table entries, dictionary entries, and objects.
23
         * This second use of objects is somewhat confusing; all items stored in the file are “objects”,
24
         * but only some of them are object objects.
25
         * Others are entities, table entries, etc.
26
         * The objects in this section can appear in any order.
27
         *
28
         * Not all objects present in the file are actually used.
29
         * The used objects can be traced back to handle references in the Header section.
30
         *
31
         * So the proper way to read a file is to start reading the header and then tracing all
32
         * references from there until all references have been followed.
33
         * Very occasionally a file contains e.g. two APPID objects with the same name,
34
         * of which one is used, and the other is not. Reading both would be incorrect due to a
35
         * name clash. To complicate matters more, files also exist with table records with duplicate
36
         * names. This is incorrect, and the software should rename the record to be unique upon reading.
37
         */
38
        internal partial class DwgObjectReader : DwgSectionIO
39
        {
40
                public override string SectionName { get { return DwgSectionDefinition.AcDbObjects; } }
×
41

42
                private long _objectInitialPos = 0;
114✔
43

44
                private uint _size;
45

46
                /// <summary>
47
                /// During the object reading the handles will be added at the queue.
48
                /// </summary>
49
                private Queue<ulong> _handles;
50

51
                private readonly Dictionary<ulong, ObjectType> _readedObjects = new Dictionary<ulong, ObjectType>();
114✔
52

53
                private readonly Dictionary<ulong, long> _map;
54

55
                private readonly Dictionary<short, DxfClass> _classes;
56

57
                private DwgDocumentBuilder _builder;
58

59
                private readonly IDwgStreamReader _reader;
60

61
                /// <summary>
62
                /// Needed to handle some items like colors or some text data that may not be present.
63
                /// </summary>
64
                private IDwgStreamReader _mergedReaders;
65

66
                /// <summary>
67
                /// Reader to handle the object data.
68
                /// </summary>
69
                private IDwgStreamReader _objectReader;
70

71
                /// <summary>
72
                /// Reader focused on the handles section of the stream.
73
                /// </summary>
74
                private IDwgStreamReader _handlesReader;
75

76
                /// <summary>
77
                /// Reader focused on the string data section of the stream.
78
                /// </summary>
79
                private IDwgStreamReader _textReader;
80

81
                /// <summary>
82
                /// Stream decoded using the crc.
83
                /// </summary>
84
                private readonly IDwgStreamReader _crcReader;
85

86
                private readonly Stream _crcStream;
87
                private readonly byte[] _crcStreamBuffer;
88

89
                private readonly byte[] _buffer;
90

91
                public DwgObjectReader(
92
                        ACadVersion version,
93
                        DwgDocumentBuilder builder,
94
                        IDwgStreamReader reader,
95
                        Queue<ulong> handles,
96
                        Dictionary<ulong, long> handleMap,
97
                        DxfClassCollection classes) : base(version)
114✔
98
                {
114✔
99
                        this._builder = builder;
114✔
100

101
                        this._reader = reader;
114✔
102

103
                        this._handles = new Queue<ulong>(handles);
114✔
104
                        this._map = new Dictionary<ulong, long>(handleMap);
114✔
105
                        this._classes = classes.ToDictionary(x => x.ClassNumber, x => x);
6,012✔
106

107
                        //Initialize the crc stream
108
                        //RS : CRC for the data section, starting after the sentinel. Use 0xC0C1 for the initial value
109
                        if (this._builder.Configuration.CrcCheck)
114!
110
                                this._crcStream = new CRC8StreamHandler(this._reader.Stream, 0xC0C1);
×
111
                        else
112
                                this._crcStream = this._reader.Stream;
114✔
113

114
                        this._crcStreamBuffer = new byte[this._crcStream.Length];
114✔
115
                        this._crcStream.Read(this._crcStreamBuffer, 0, this._crcStreamBuffer.Length);
114✔
116

117
                        this._crcStream.Position = 0L;
114✔
118

119
                        //Setup the entity handler
120
                        this._crcReader = DwgStreamReaderBase.GetStreamHandler(this._version, this._crcStream);
114✔
121
                }
114✔
122

123
                /// <summary>
124
                /// Read all the entities, tables and objects in the file.
125
                /// </summary>
126
                public void Read()
127
                {
114✔
128
                        //Read each handle in the header
129
                        while (this._handles.Any())
58,797✔
130
                        {
58,683✔
131
                                ulong handle = this._handles.Dequeue();
58,683✔
132

133
                                //Check if the handle has already been read
134
                                if (!this._map.TryGetValue(handle, out long offset) ||
58,683✔
135
                                        this._builder.TryGetObjectTemplate(handle, out CadTemplate _) ||
58,683✔
136
                                        this._readedObjects.ContainsKey(handle))
58,683✔
137
                                {
9,266✔
138
                                        continue;
9,266✔
139
                                }
140

141
                                //Get the object type
142
                                ObjectType type = this.getEntityType(offset);
49,417✔
143
                                //Save the object to avoid infinite loops while reading
144
                                this._readedObjects.Add(handle, type);
49,417✔
145

146
                                CadTemplate template = null;
49,417✔
147

148
                                try
149
                                {
49,417✔
150
                                        //Read the object
151
                                        template = this.readObject(type);
49,417✔
152
                                }
49,417✔
153
                                catch (Exception ex)
×
154
                                {
×
155
                                        if (!this._builder.Configuration.Failsafe)
×
156
                                                throw;
×
157

158
                                        if (this._classes.TryGetValue((short)type, out DxfClass dxf))
×
159
                                        {
×
160
                                                this._builder.Notify($"Could not read {dxf.DxfName} number {dxf.ClassNumber} with handle: {handle}", NotificationType.Error, ex);
×
161
                                        }
×
162
                                        else
163
                                        {
×
164
                                                this._builder.Notify($"Could not read {type} with handle: {handle}", NotificationType.Error, ex);
×
165
                                        }
×
166

167
                                        continue;
×
168
                                }
169

170
                                //Add the template to the list to be processed
171
                                if (template == null)
49,417✔
172
                                        continue;
339✔
173

174
                                this._builder.AddTemplate(template);
49,078✔
175
                        }
49,078✔
176
                }
114✔
177

178
                private ObjectType getEntityType(long offset)
179
                {
49,417✔
180
                        ObjectType type = ObjectType.INVALID;
49,417✔
181

182
                        //Set the position to the entity to find
183
                        this._crcReader.Position = offset;
49,417✔
184

185
                        //MS : Size of object, not including the CRC
186
                        this._size = (uint)this._crcReader.ReadModularShort();
49,417✔
187

188
                        if (this._size <= 0U)
49,417!
189
                                return type;
×
190

191
                        //remove the padding bits make sure the object stream ends on a byte boundary
192
                        uint sizeInBits = (uint)(this._size << 3);
49,417✔
193

194
                        //R2010+:
195
                        if (this.R2010Plus)
49,417✔
196
                        {
19,298✔
197
                                //MC : Size in bits of the handle stream (unsigned, 0x40 is not interpreted as sign).
198
                                //This includes the padding bits at the end of the handle stream
199
                                //(the padding bits make sure the object stream ends on a byte boundary).
200
                                ulong handleSize = this._crcReader.ReadModularChar();
19,298✔
201

202
                                //Find the handles offset
203
                                ulong handleSectionOffset = (ulong)this._crcReader.PositionInBits() + sizeInBits - handleSize;
19,298✔
204

205
                                //Create a handler section reader
206
                                this._objectReader = DwgStreamReaderBase.GetStreamHandler(this._version, new MemoryStream(this._crcStreamBuffer), this._reader.Encoding);
19,298✔
207
                                this._objectReader.SetPositionInBits(this._crcReader.PositionInBits());
19,298✔
208

209
                                //set the initial posiltion and get the object type
210
                                this._objectInitialPos = this._objectReader.PositionInBits();
19,298✔
211
                                type = this._objectReader.ReadObjectType();
19,298✔
212

213

214
                                //Create a handler section reader
215
                                this._handlesReader = DwgStreamReaderBase.GetStreamHandler(this._version, new MemoryStream(this._crcStreamBuffer), this._reader.Encoding);
19,298✔
216
                                this._handlesReader.SetPositionInBits((long)handleSectionOffset);
19,298✔
217

218
                                //Create a text section reader
219
                                this._textReader = DwgStreamReaderBase.GetStreamHandler(this._version, new MemoryStream(this._crcStreamBuffer), this._reader.Encoding);
19,298✔
220
                                this._textReader.SetPositionByFlag((long)handleSectionOffset - 1);
19,298✔
221

222
                                this._mergedReaders = new DwgMergedReader(this._objectReader, this._textReader, this._handlesReader);
19,298✔
223
                        }
19,298✔
224
                        else
225
                        {
30,119✔
226
                                //Create a handler section reader
227
                                this._objectReader = DwgStreamReaderBase.GetStreamHandler(this._version, new MemoryStream(this._crcStreamBuffer), this._reader.Encoding);
30,119✔
228
                                this._objectReader.SetPositionInBits(this._crcReader.PositionInBits());
30,119✔
229

230
                                this._handlesReader = DwgStreamReaderBase.GetStreamHandler(this._version, new MemoryStream(this._crcStreamBuffer), this._reader.Encoding);
30,119✔
231
                                this._textReader = this._objectReader;
30,119✔
232

233
                                //set the initial posiltion and get the object type
234
                                this._objectInitialPos = this._objectReader.PositionInBits();
30,119✔
235
                                type = this._objectReader.ReadObjectType();
30,119✔
236
                        }
30,119✔
237

238
                        return type;
49,417✔
239
                }
49,417✔
240

241
                #region Common entity data
242

243
                /// <summary>
244
                /// Get the handle of the entity and saves the value to the <see cref="_handles"/>
245
                /// </summary>
246
                /// <returns>the handle to reference into the entity</returns>
247
                private ulong handleReference()
248
                {
128,073✔
249
                        return this.handleReference(0);
128,073✔
250
                }
128,073✔
251

252
                /// <summary>
253
                /// Get the handle of the entity and saves the value to the <see cref="_handles"/>
254
                /// </summary>
255
                /// <returns>the handle to reference into the entity</returns>
256
                private ulong handleReference(ulong handle)
257
                {
163,231✔
258
                        //Read the handle
259
                        ulong value = this._handlesReader.HandleReference(handle);
163,231✔
260

261
                        if (value != 0 &&
163,231✔
262
                                !this._builder.TryGetObjectTemplate(value, out CadTemplate _) &&
163,231✔
263
                                !this._readedObjects.ContainsKey(value))
163,231✔
264
                        {
51,298✔
265
                                //Add the value to the handles queue to be processed
266
                                this._handles.Enqueue(value);
51,298✔
267
                        }
51,298✔
268

269
                        return value;
163,231✔
270
                }
163,231✔
271

272
                private void readCommonData(CadTemplate template)
273
                {
49,078✔
274
                        if (this._version >= ACadVersion.AC1015 && this._version < ACadVersion.AC1024)
49,078✔
275
                                //Obj size RL size of object in bits, not including end handles
276
                                this.updateHandleReader();
20,744✔
277

278
                        //Common:
279
                        //Handle H 5 code 0, length followed by the handle bytes.
280
                        template.CadObject.Handle = this._objectReader.HandleReference();
49,078✔
281

282
                        //Extended object data, if any
283
                        this.readExtendedData(template);
49,078✔
284
                }
49,078✔
285

286
                // Read the common entity format.
287
                private void readCommonEntityData(CadEntityTemplate template)
288
                {
19,950✔
289
                        //Get the cad object as an entity
290
                        Entity entity = template.CadObject;
19,950✔
291

292
                        this.readCommonData(template);
19,950✔
293

294
                        //Graphic present Flag B 1 if a graphic is present
295
                        if (this._objectReader.ReadBit())
19,950✔
296
                        {
546✔
297
                                //Graphics X if graphicpresentflag is 1, the graphic goes here.
298
                                //See the section on Proxy Entity Graphics for the format of this section.
299

300
                                //R13 - R007:
301
                                //RL: Size of graphic image in bytes
302
                                //R2010 +:
303
                                //BLL: Size of graphic image in bytes
304
                                long graphicImageSize = this._version >= ACadVersion.AC1024 ?
546✔
305
                                        this._objectReader.ReadBitLongLong() : this._objectReader.ReadRawLong();
546✔
306

307
                                //Common:
308
                                //X: The graphic image
309
                                //entityHandler.CadObject.JumpGraphicImage(this, entityHandler, graphicImageSize);
310
                                this._objectReader.Advance((int)graphicImageSize);
546✔
311
                        }
546✔
312

313
                        //R13 - R14 Only:
314
                        if (this._version >= ACadVersion.AC1012 && this._version <= ACadVersion.AC1014)
19,950!
315
                        {
2,872✔
316
                                this.updateHandleReader();
2,872✔
317
                        }
2,872✔
318

319
                        this.readEntityMode(template);
19,950✔
320
                }
19,950✔
321

322
                private void readEntityMode(CadEntityTemplate template)
323
                {
19,972✔
324
                        //Get the cad object as an entity
325
                        Entity entity = template.CadObject;
19,972✔
326

327
                        //Common:
328
                        //6B : Flags
329
                        //Entmode BB entity mode
330
                        template.EntityMode = this._objectReader.Read2Bits();
19,972✔
331

332
                        //FE: Entity mode(entmode). Generally, this indicates whether or not the owner
333
                        //relative handle reference is present.The values go as follows:
334

335
                        //00 : The owner relative handle reference is present.
336
                        //Applies to the following:
337
                        //VERTEX, ATTRIB, and SEQEND.
338
                        //BLOCK, ENDBLK, and the defining entities in all
339
                        //block defs except *MODEL_SPACE and * PAPER_SPACE.
340

341
                        //01 : PSPACE entity without a owner relative handle ref.
342
                        //10 : MSPACE entity without a owner relative handle ref.
343
                        //11 : Not used.
344

345
                        if (template.EntityMode == 0)
19,972✔
346
                        {
11,914✔
347
                                template.OwnerHandle = this._handlesReader.HandleReference(entity.Handle);
11,914✔
348
                        }
11,914✔
349
                        else if (template.EntityMode == 1)
8,058✔
350
                        {
382✔
351
                                this._builder.PaperSpaceEntities.Add(entity);
382✔
352
                        }
382✔
353
                        else if (template.EntityMode == 2)
7,676✔
354
                        {
7,676✔
355
                                this._builder.ModelSpaceEntities.Add(entity);
7,676✔
356
                        }
7,676✔
357

358
                        //Numreactors BL number of persistent reactors attached to this object
359
                        this.readReactorsAndDictionaryHandle(template);
19,972✔
360

361
                        //R13-R14 Only:
362
                        if (this.R13_14Only)
19,972✔
363
                        {
2,872✔
364
                                //8 LAYER (hard pointer)
365
                                template.LayerHandle = this.handleReference();
2,872✔
366

367
                                //Isbylayerlt B 1 if bylayer linetype, else 0
368
                                if (!this._objectReader.ReadBit())
2,872✔
369
                                        //6 [LTYPE (hard pointer)] (present if Isbylayerlt is 0)
370
                                        template.LineTypeHandle = this.handleReference();
363✔
371
                        }
2,872✔
372

373
                        //R13-R2000 Only:
374
                        //previous/next handles present if Nolinks is 0.
375
                        //Nolinks B 1 if major links are assumed +1, -1, else 0 For R2004+this always has value 1 (links are not used)
376
                        if (!this.R2004Plus && !this._objectReader.ReadBit())
19,972✔
377
                        {
3,015✔
378
                                //[PREVIOUS ENTITY (relative soft pointer)]
379
                                template.PrevEntity = this.handleReference(entity.Handle);
3,015✔
380
                                //[NEXT ENTITY (relative soft pointer)]
381
                                template.NextEntity = this.handleReference(entity.Handle);
3,015✔
382
                        }
3,015✔
383
                        else if (!this.R2004Plus)
16,957✔
384
                        {
2,685✔
385
                                if (!this._readedObjects.ContainsKey(entity.Handle - 1UL))
2,685✔
386
                                        this._handles.Enqueue(entity.Handle - 1UL);
1,200✔
387
                                if (!this._readedObjects.ContainsKey(entity.Handle + 1UL))
2,685✔
388
                                        this._handles.Enqueue(entity.Handle + 1UL);
1,122✔
389
                        }
2,685✔
390

391
                        //Color        CMC(B)        62
392
                        entity.Color = this._objectReader.ReadEnColor(out Transparency transparency, out bool colorFlag);
19,972✔
393
                        entity.Transparency = transparency;
19,972✔
394

395
                        //R2004+:
396
                        if ((this._version >= ACadVersion.AC1018) && colorFlag)
19,972!
397
                                //[Color book color handle (hard pointer)]
398
                                template.ColorHandle = this.handleReference();
×
399

400
                        //Ltype scale        BD        48
401
                        entity.LinetypeScale = this._objectReader.ReadBitDouble();
19,972✔
402

403
                        if (!(this._version >= ACadVersion.AC1015))
19,972✔
404
                        {
2,872✔
405
                                //Common:
406
                                //Invisibility BS 60
407
                                entity.IsInvisible = (this._objectReader.ReadBitShort() & 1) == 0;
2,872✔
408

409
                                return;
2,872✔
410
                        }
411

412
                        //R2000+:
413
                        //8 LAYER (hard pointer)
414
                        template.LayerHandle = this.handleReference();
17,100✔
415

416
                        //Ltype flags BB 00 = bylayer, 01 = byblock, 10 = continous, 11 = linetype handle present at end of object
417
                        template.LtypeFlags = this._objectReader.Read2Bits();
17,100✔
418

419
                        if (template.LtypeFlags == 3)
17,100!
420
                                //6 [LTYPE (hard pointer)] present if linetype flags were 11
421
                                template.LineTypeHandle = this.handleReference();
814✔
422

423
                        //R2007+:
424
                        if (this.R2007Plus)
17,100✔
425
                        {
11,437✔
426
                                //Material flags BB 00 = bylayer, 01 = byblock, 11 = material handle present at end of object
427
                                if (this._objectReader.Read2Bits() == 3)
11,437✔
428
                                {
22✔
429
                                        //MATERIAL present if material flags were 11
430
                                        template.MaterialHandle = this.handleReference();
22✔
431
                                }
22✔
432

433
                                //Shadow flags RC
434
                                this._objectReader.ReadByte();
11,437✔
435
                        }
11,437✔
436

437
                        //R2000 +:
438
                        //Plotstyle flags        BB        00 = bylayer, 01 = byblock, 11 = plotstyle handle present at end of object
439
                        if (this._objectReader.Read2Bits() == 3)
17,100!
440
                        {
×
441
                                //PLOTSTYLE (hard pointer) present if plotstyle flags were 11
442
                                long plotstyleFlags = (long)this.handleReference();
×
443
                        }
×
444

445
                        //R2007 +:
446
                        if (this.R2010Plus)
17,100✔
447
                        {
8,599✔
448
                                //Material flags BB 00 = bylayer, 01 = byblock, 11 = material handle present at end of object
449
                                if (this._objectReader.ReadBit())
8,599!
450
                                {
×
451
                                        //If has full visual style, the full visual style handle (hard pointer).
452
                                        long n = (long)this.handleReference();
×
453
                                }
×
454
                                if (this._objectReader.ReadBit())
8,599!
455
                                {
×
456
                                        //If has full visual style, the full visual style handle (hard pointer).
457
                                        long n = (long)this.handleReference();
×
458
                                }
×
459
                                //Shadow flags RC
460
                                if (this._objectReader.ReadBit())
8,599!
461
                                {
×
462
                                        //If has full visual style, the full visual style handle (hard pointer).
463
                                        long n = (long)this.handleReference();
×
464
                                }
×
465
                        }
8,599✔
466

467
                        //Common:
468
                        //Invisibility BS 60
469
                        entity.IsInvisible = (this._objectReader.ReadBitShort() & 1) == 1;
17,100✔
470

471
                        //R2000+:
472
                        //Lineweight RC 370
473
                        entity.LineWeight = CadUtils.ToValue(this._objectReader.ReadByte());
17,100✔
474
                }
19,972✔
475

476
                private void readCommonNonEntityData(CadTemplate template)
477
                {
29,128✔
478
                        this.readCommonData(template);
29,128✔
479

480
                        //R13-R14 Only:
481
                        //Obj size RL size of object in bits, not including end handles
482
                        if (this.R13_14Only)
29,128✔
483
                                this.updateHandleReader();
6,266✔
484

485
                        //[Owner ref handle (soft pointer)]
486
                        template.OwnerHandle = this.handleReference(template.CadObject.Handle);
29,128✔
487

488
                        //Read the cad object reactors
489
                        this.readReactorsAndDictionaryHandle(template);
29,128✔
490
                }
29,128✔
491

492
                private void readXrefDependantBit(TableEntry entry)
493
                {
5,882✔
494
                        if (this.R2007Plus)
5,882✔
495
                        {
3,302✔
496
                                //xrefindex+1 BS 70 subtract one from this value when read.
497
                                //After that, -1 indicates that this reference did not come from an xref,
498
                                //otherwise this value indicates the index of the blockheader for the xref from which this came.
499
                                short xrefindex = this._objectReader.ReadBitShort();
3,302✔
500

501
                                //Xdep B 70 dependent on an xref. (16 bit)
502
                                if (((uint)xrefindex & 0b100000000) > 0)
3,302!
503
                                        entry.Flags |= StandardFlags.XrefDependent;
×
504
                        }
3,302✔
505
                        else
506
                        {
2,580✔
507
                                //64-flag B 70 The 64-bit of the 70 group.
508
                                if (this._objectReader.ReadBit())
2,580✔
509
                                        entry.Flags |= StandardFlags.Referenced;
2,436✔
510

511
                                //xrefindex + 1 BS 70 subtract one from this value when read.
512
                                //After that, -1 indicates that this reference did not come from an xref,
513
                                //otherwise this value indicates the index of the blockheader for the xref from which this came.
514
                                int xrefindex = this._objectReader.ReadBitShort() - 1;
2,580✔
515

516
                                //Xdep B 70 dependent on an xref. (16 bit)
517
                                if (this._objectReader.ReadBit())
2,580!
518
                                        entry.Flags |= StandardFlags.XrefDependent;
×
519
                        }
2,580✔
520
                }
5,882✔
521

522
                private void readExtendedData(CadTemplate template)
523
                {
49,078✔
524
                        //EED directly follows the entity handle.
525
                        //Each application's data is structured as follows:
526
                        //|Length|Application handle|Data items|
527

528
                        //EED size BS size of extended entity data, if any
529
                        short size = this._objectReader.ReadBitShort();
49,078✔
530

531
                        while (size != 0)
57,994✔
532
                        {
8,916✔
533
                                //App handle
534
                                ulong appHandle = this._objectReader.HandleReference();
8,916✔
535
                                long endPos = this._objectReader.Position + size;
8,916✔
536

537
                                //template.ExtendedData
538
                                ExtendedData edata = this.readExtendedDataRecords(endPos);
8,916✔
539

540
                                template.EDataTemplate.Add(appHandle, edata);
8,916✔
541

542
                                size = this._objectReader.ReadBitShort();
8,916✔
543
                        }
8,916✔
544
                }
49,078✔
545

546
                private ExtendedData readExtendedDataRecords(long endPos)
547
                {
8,916✔
548
                        ExtendedData data = new ExtendedData();
8,916✔
549

550
                        while (this._objectReader.Position < endPos)
39,029✔
551
                        {
30,113✔
552
                                //Each data item has a 1-byte code (DXF group code minus 1000) followed by the value.
553
                                DxfCode dxfCode = (DxfCode)(1000 + this._objectReader.ReadByte());
30,113✔
554

555
                                ExtendedDataRecord record = null;
30,113✔
556

557
                                switch (dxfCode)
30,113!
558
                                {
559
                                        //0 (1000) String.
560
                                        case DxfCode.ExtendedDataAsciiString:
561
                                        //R13-R2004: 1st byte of value is the length N; this is followed by a 2-byte short indicating the codepage, followed by N single-byte characters.
562
                                        //R2007 +: 2 - byte length N, followed by N Unicode characters(2 bytes each).
563
                                        case DxfCode.ExtendedDataRegAppName:
564
                                                //1 (1001) This one seems to be invalid; can't even use as a string inside braces.
565
                                                //This would be a registered application that this data relates to, but we've already had that above, 
566
                                                //so it would be redundant or irrelevant here.
567
                                                record = new ExtendedDataRecord(dxfCode, this._objectReader.ReadTextUnicode());
8,531✔
568
                                                break;
8,531✔
569
                                        case DxfCode.ExtendedDataControlString:
570
                                                //2 (1002) A '{' or '}'; 1 byte; ASCII 0 means '{', ASCII 1 means '}'
571
                                                record = new ExtendedDataRecord(dxfCode, this._objectReader.ReadByte());
2,060✔
572
                                                break;
2,060✔
573
                                        case DxfCode.ExtendedDataLayerName:
574
                                                //3 (1003) A layer table reference. The value is the handle of the layer;
575
                                                //it's 8 bytes -- even if the leading ones are 0. It's not a string; read 
576
                                                //it as hex, as usual for handles. (There's no length specifier this time.) 
577
                                                //Even layer 0 is referred to by handle here.
578
                                                byte[] arr = this._objectReader.ReadBytes(8);
×
579
                                                ulong handle = BigEndianConverter.Instance.ToUInt64(arr);
×
580
                                                record = new ExtendedDataRecord(dxfCode, handle);
×
581
                                                break;
×
582
                                        case DxfCode.ExtendedDataBinaryChunk:
583
                                                //4 (1004) Binary chunk. The first byte of the value is a char giving the length; the bytes follow.
584
                                                record = new ExtendedDataRecord(dxfCode, this._objectReader.ReadBytes(this._objectReader.ReadByte()));
364✔
585
                                                break;
364✔
586
                                        case DxfCode.ExtendedDataHandle:
587
                                                //5 (1005) An entity handle reference.
588
                                                //The value is given as 8 bytes -- even if the leading ones are 0.
589
                                                //It's not a string; read it as hex, as usual for handles.
590
                                                //(There's no length specifier this time.)
591
                                                arr = this._objectReader.ReadBytes(8);
165✔
592
                                                handle = BigEndianConverter.Instance.ToUInt64(arr);
165✔
593
                                                record = new ExtendedDataRecord(dxfCode, handle);
165✔
594
                                                break;
165✔
595
                                        //10 - 13 (1010 - 1013)
596
                                        case DxfCode.ExtendedDataXCoordinate:
597
                                        case DxfCode.ExtendedDataWorldXCoordinate:
598
                                        case DxfCode.ExtendedDataWorldYCoordinate:
599
                                        case DxfCode.ExtendedDataWorldZCoordinate:
600
                                        case DxfCode.ExtendedDataWorldXDisp:
601
                                        case DxfCode.ExtendedDataWorldYDisp:
602
                                        case DxfCode.ExtendedDataWorldZDisp:
603
                                        case DxfCode.ExtendedDataWorldXDir:
604
                                        case DxfCode.ExtendedDataWorldYDir:
605
                                        case DxfCode.ExtendedDataWorldZDir:
606
                                                //Points; 24 bytes(XYZ)-- 3 doubles
607
                                                record = new ExtendedDataRecord(
440✔
608
                                                        dxfCode,
440✔
609
                                                        new XYZ(
440✔
610
                                                                this._objectReader.ReadDouble(),
440✔
611
                                                                this._objectReader.ReadDouble(),
440✔
612
                                                                this._objectReader.ReadDouble()
440✔
613
                                                                )
440✔
614
                                                        );
440✔
615
                                                break;
440✔
616
                                        //40 - 42 (1040 - 1042)
617
                                        case DxfCode.ExtendedDataReal:
618
                                        case DxfCode.ExtendedDataDist:
619
                                        case DxfCode.ExtendedDataScale:
620
                                                //Reals; 8 bytes(double)
621
                                                record = new ExtendedDataRecord(dxfCode, this._objectReader.ReadDouble());
2,697✔
622
                                                break;
2,697✔
623
                                        //70(1070) A short int; 2 bytes
624
                                        case DxfCode.ExtendedDataInteger16:
625
                                                record = new ExtendedDataRecord(dxfCode, this._objectReader.ReadShort());
14,210✔
626
                                                break;
14,210✔
627
                                        //71(1071) A long int; 4 bytes
628
                                        case DxfCode.ExtendedDataInteger32:
629
                                                record = new ExtendedDataRecord(dxfCode, this._objectReader.ReadRawLong());
1,646✔
630
                                                break;
1,646✔
631
                                        default:
632
                                                this._objectReader.ReadBytes((int)(endPos - this._objectReader.Position));
×
633
                                                this._builder.Notify($"Unknown code for extended data: {dxfCode}", NotificationType.Warning);
×
634
                                                return data;
×
635
                                }
636

637
                                data.Data.Add(record);
30,113✔
638
                        }
30,113✔
639

640
                        return data;
8,916✔
641
                }
8,916✔
642

643
                // Add the reactors to the template.
644
                private void readReactorsAndDictionaryHandle(CadTemplate template)
645
                {
49,100✔
646
                        //Numreactors S number of reactors in this object
647
                        int numberOfReactors = this._objectReader.ReadBitLong();
49,100✔
648

649
                        //Add the reactors to the template
650
                        for (int i = 0; i < numberOfReactors; ++i)
136,998✔
651
                                //[Reactors (soft pointer)]
652
                                template.ReactorsHandles.Add(this.handleReference());
19,399✔
653

654
                        bool flag = false;
49,100✔
655
                        //R2004+:
656
                        if (this.R2004Plus)
49,100✔
657
                                /*XDic Missing Flag
658
                                 * B
659
                                 * If 1, no XDictionary handle is stored for this object,
660
                                 * otherwise XDictionary handle is stored as in R2000 and earlier.
661
                                */
662
                                flag = this._objectReader.ReadBit();
32,892✔
663

664
                        if (!flag)
49,100✔
665
                                //xdicobjhandle(hard owner)
666
                                template.XDictHandle = this.handleReference();
18,939✔
667

668
                        //R2013+:
669
                        if (this.R2013Plus)
49,100✔
670
                        {
12,433✔
671
                                //Has DS binary data B If 1 then this object has associated binary data stored in the data store
672
                                this._objectReader.ReadBit();
12,433✔
673
                        }
12,433✔
674
                }
49,100✔
675

676
                /// <summary>
677
                /// Update the text reader and the handler reader at the end of the object position.
678
                /// </summary>
679
                private void updateHandleReader()
680
                {
29,882✔
681
                        //RL: Size of object data in bits (number of bits before the handles),
682
                        //or the "endbit" of the pre-handles section.
683
                        long size = this._objectReader.ReadRawLong();
29,882✔
684

685
                        //Set the position to the handle section
686
                        this._handlesReader.SetPositionInBits(size + this._objectInitialPos);
29,882✔
687

688
                        if (this._version == ACadVersion.AC1021)
29,882✔
689
                        {
6,672✔
690
                                this._textReader = DwgStreamReaderBase.GetStreamHandler(this._version, new MemoryStream(this._crcStreamBuffer), this._reader.Encoding);
6,672✔
691
                                //"endbit" of the pre-handles section.
692
                                this._textReader.SetPositionByFlag(size + this._objectInitialPos - 1);
6,672✔
693
                        }
6,672✔
694

695
                        this._mergedReaders = new DwgMergedReader(this._objectReader, this._textReader, this._handlesReader);
29,882✔
696
                }
29,882✔
697

698
                #endregion Common entity data
699

700
                #region Object readers
701

702
                private CadTemplate readObject(ObjectType type)
703
                {
49,417✔
704
                        CadTemplate template = null;
49,417✔
705

706
                        switch (type)
49,417!
707
                        {
708
                                case ObjectType.UNDEFINED:
709
                                        break;
×
710
                                case ObjectType.TEXT:
711
                                        template = this.readText();
624✔
712
                                        break;
624✔
713
                                case ObjectType.ATTRIB:
714
                                        template = this.readAttribute();
308✔
715
                                        break;
308✔
716
                                case ObjectType.ATTDEF:
717
                                        template = this.readAttributeDefinition();
385✔
718
                                        break;
385✔
719
                                case ObjectType.BLOCK:
720
                                        template = this.readBlock();
1,323✔
721
                                        break;
1,323✔
722
                                case ObjectType.ENDBLK:
723
                                        template = this.readEndBlock();
1,323✔
724
                                        break;
1,323✔
725
                                case ObjectType.SEQEND:
726
                                        template = this.readSeqend();
308✔
727
                                        break;
308✔
728
                                case ObjectType.INSERT:
729
                                        template = this.readInsert();
385✔
730
                                        break;
385✔
731
                                case ObjectType.MINSERT:
732
                                        template = this.readMInsert();
8✔
733
                                        break;
8✔
734
                                case ObjectType.UNKNOW_9:
735
                                        break;
×
736
                                case ObjectType.VERTEX_2D:
737
                                        template = this.readVertex2D();
×
738
                                        break;
×
739
                                case ObjectType.VERTEX_3D:
740
                                        template = this.readVertex3D(new Vertex3D());
385✔
741
                                        break;
385✔
742
                                case ObjectType.VERTEX_MESH:
743
                                        break;
×
744
                                case ObjectType.VERTEX_PFACE:
745
                                        template = this.readVertex3D(new VertexFaceMesh());
385✔
746
                                        break;
385✔
747
                                case ObjectType.VERTEX_PFACE_FACE:
748
                                        template = this.readPfaceVertex();
154✔
749
                                        break;
154✔
750
                                case ObjectType.POLYLINE_2D:
751
                                        template = this.readPolyline2D();
×
752
                                        break;
×
753
                                case ObjectType.POLYLINE_3D:
754
                                        template = this.readPolyline3D();
77✔
755
                                        break;
77✔
756
                                case ObjectType.ARC:
757
                                        template = this.readArc();
239✔
758
                                        break;
239✔
759
                                case ObjectType.CIRCLE:
760
                                        template = this.readCircle();
316✔
761
                                        break;
316✔
762
                                case ObjectType.LINE:
763
                                        template = this.readLine();
4,944✔
764
                                        break;
4,944✔
765
                                case ObjectType.DIMENSION_ORDINATE:
766
                                        template = this.readDimOrdinate();
162✔
767
                                        break;
162✔
768
                                case ObjectType.DIMENSION_LINEAR:
769
                                        template = this.readDimLinear();
85✔
770
                                        break;
85✔
771
                                case ObjectType.DIMENSION_ALIGNED:
772
                                        template = this.readDimAligned();
85✔
773
                                        break;
85✔
774
                                case ObjectType.DIMENSION_ANG_3_Pt:
775
                                        template = this.readDimAngular3pt();
85✔
776
                                        break;
85✔
777
                                case ObjectType.DIMENSION_ANG_2_Ln:
778
                                        template = this.readDimLine2pt();
85✔
779
                                        break;
85✔
780
                                case ObjectType.DIMENSION_RADIUS:
781
                                        template = this.readDimRadius();
85✔
782
                                        break;
85✔
783
                                case ObjectType.DIMENSION_DIAMETER:
784
                                        template = this.readDimDiameter();
85✔
785
                                        break;
85✔
786
                                case ObjectType.POINT:
787
                                        template = this.readPoint();
2,401✔
788
                                        break;
2,401✔
789
                                case ObjectType.FACE3D:
790
                                        template = this.read3dFace();
77✔
791
                                        break;
77✔
792
                                case ObjectType.POLYLINE_PFACE:
793
                                        template = this.readPolyfaceMesh();
77✔
794
                                        break;
77✔
795
                                case ObjectType.POLYLINE_MESH:
796
                                        template = this.readPolylineMesh();
×
797
                                        break;
×
798
                                case ObjectType.SOLID:
799
                                case ObjectType.TRACE:
800
                                        template = this.readSolid();
770✔
801
                                        break;
770✔
802
                                case ObjectType.SHAPE:
803
                                        template = this.readShape();
77✔
804
                                        break;
77✔
805
                                case ObjectType.VIEWPORT:
806
                                        template = this.readViewport();
462✔
807
                                        break;
462✔
808
                                case ObjectType.ELLIPSE:
809
                                        template = this.readEllipse();
85✔
810
                                        break;
85✔
811
                                case ObjectType.SPLINE:
812
                                        template = this.readSpline();
154✔
813
                                        break;
154✔
814
                                case ObjectType.REGION:
815
                                        break;
×
816
                                case ObjectType.SOLID3D:
817
                                        break;
×
818
                                case ObjectType.BODY:
819
                                        break;
×
820
                                case ObjectType.RAY:
821
                                        template = this.readRay();
77✔
822
                                        break;
77✔
823
                                case ObjectType.XLINE:
824
                                        template = this.readXLine();
77✔
825
                                        break;
77✔
826
                                case ObjectType.DICTIONARY:
827
                                        template = this.readDictionary();
7,666✔
828
                                        break;
7,666✔
829
                                case ObjectType.OLEFRAME:
830
                                        break;
×
831
                                case ObjectType.MTEXT:
832
                                        template = this.readMText();
1,617✔
833
                                        break;
1,617✔
834
                                case ObjectType.LEADER:
835
                                        template = this.readLeader();
77✔
836
                                        break;
77✔
837
                                case ObjectType.TOLERANCE:
838
                                        template = this.readTolerance();
231✔
839
                                        break;
231✔
840
                                case ObjectType.MLINE:
841
                                        template = this.readMLine();
231✔
842
                                        break;
231✔
843
                                case ObjectType.BLOCK_CONTROL_OBJ:
844
                                        template = this.readBlockControlObject();
114✔
845
                                        this._builder.BlockRecords = (BlockRecordsTable)template.CadObject;
114✔
846
                                        break;
114✔
847
                                case ObjectType.BLOCK_HEADER:
848
                                        template = this.readBlockHeader();
1,323✔
849
                                        break;
1,323✔
850
                                case ObjectType.LAYER_CONTROL_OBJ:
851
                                        template = this.readDocumentTable(new LayersTable());
114✔
852
                                        this._builder.Layers = (LayersTable)template.CadObject;
114✔
853
                                        break;
114✔
854
                                case ObjectType.LAYER:
855
                                        template = this.readLayer();
1,436✔
856
                                        break;
1,436✔
857
                                case ObjectType.STYLE_CONTROL_OBJ:
858
                                        template = this.readDocumentTable(new TextStylesTable());
114✔
859
                                        this._builder.TextStyles = (TextStylesTable)template.CadObject;
114✔
860
                                        break;
114✔
861
                                case ObjectType.STYLE:
862
                                        template = this.readTextStyle();
508✔
863
                                        break;
508✔
864
                                case ObjectType.UNKNOW_36:
865
                                        break;
×
866
                                case ObjectType.UNKNOW_37:
867
                                        break;
×
868
                                case ObjectType.LTYPE_CONTROL_OBJ:
869
                                        template = this.readLTypeControlObject();
114✔
870
                                        this._builder.LineTypesTable = (LineTypesTable)template.CadObject;
114✔
871
                                        break;
114✔
872
                                case ObjectType.LTYPE:
873
                                        template = this.readLType();
727✔
874
                                        break;
727✔
875
                                case ObjectType.UNKNOW_3A:
876
                                        break;
×
877
                                case ObjectType.UNKNOW_3B:
878
                                        break;
×
879
                                case ObjectType.VIEW_CONTROL_OBJ:
880
                                        template = this.readDocumentTable(new ViewsTable());
114✔
881
                                        this._builder.Views = (ViewsTable)template.CadObject;
114✔
882
                                        break;
114✔
883
                                case ObjectType.VIEW:
884
                                        template = this.readView();
77✔
885
                                        break;
77✔
886
                                case ObjectType.UCS_CONTROL_OBJ:
887
                                        template = this.readDocumentTable(new UCSTable());
114✔
888
                                        this._builder.UCSs = (UCSTable)template.CadObject;
114✔
889
                                        break;
114✔
890
                                case ObjectType.UCS:
891
                                        template = this.readUcs();
×
892
                                        break;
×
893
                                case ObjectType.VPORT_CONTROL_OBJ:
894
                                        template = this.readDocumentTable(new VPortsTable());
114✔
895
                                        this._builder.VPorts = (VPortsTable)template.CadObject;
114✔
896
                                        break;
114✔
897
                                case ObjectType.VPORT:
898
                                        template = this.readVPort();
114✔
899
                                        break;
114✔
900
                                case ObjectType.APPID_CONTROL_OBJ:
901
                                        template = this.readDocumentTable(new AppIdsTable());
114✔
902
                                        this._builder.AppIds = (AppIdsTable)template.CadObject;
114✔
903
                                        break;
114✔
904
                                case ObjectType.APPID:
905
                                        template = this.readAppId();
1,412✔
906
                                        break;
1,412✔
907
                                case ObjectType.DIMSTYLE_CONTROL_OBJ:
908
                                        template = this.readDocumentTable(new DimensionStylesTable());
114✔
909
                                        this._builder.DimensionStyles = (DimensionStylesTable)template.CadObject;
114✔
910
                                        break;
114✔
911
                                case ObjectType.DIMSTYLE:
912
                                        template = this.readDimStyle();
285✔
913
                                        break;
285✔
914
                                case ObjectType.VP_ENT_HDR_CTRL_OBJ:
915
                                        template = this.readViewportEntityControl();
23✔
916
                                        break;
23✔
917
                                case ObjectType.VP_ENT_HDR:
918
                                        template = this.readViewportEntityHeader();
44✔
919
                                        break;
44✔
920
                                case ObjectType.GROUP:
921
                                        template = this.readGroup();
154✔
922
                                        break;
154✔
923
                                case ObjectType.MLINESTYLE:
924
                                        template = this.readMLineStyle();
114✔
925
                                        break;
114✔
926
                                case ObjectType.OLE2FRAME:
927
                                        break;
×
928
                                case ObjectType.DUMMY:
929
                                        break;
×
930
                                case ObjectType.LONG_TRANSACTION:
931
                                        break;
×
932
                                case ObjectType.LWPOLYLINE:
933
                                        template = this.readLWPolyline();
726✔
934
                                        break;
726✔
935
                                case ObjectType.HATCH:
936
                                        template = this.readHatch();
264✔
937
                                        break;
264✔
938
                                case ObjectType.XRECORD:
939
                                        template = this.readXRecord();
3,922✔
940
                                        break;
3,922✔
941
                                case ObjectType.ACDBPLACEHOLDER:
942
                                        template = this.readPlaceHolder();
63✔
943
                                        break;
63✔
944
                                case ObjectType.VBA_PROJECT:
945
                                        break;
×
946
                                case ObjectType.LAYOUT:
947
                                        template = this.readLayout();
300✔
948
                                        break;
300✔
949
                                case ObjectType.ACAD_PROXY_ENTITY:
950
                                        break;
×
951
                                case ObjectType.ACAD_PROXY_OBJECT:
952
                                        break;
×
953
                                default:
954
                                        return this.readUnlistedType((short)type);
10,984✔
955
                        }
956

957
                        if (template == null)
38,433✔
958
                                this._builder.Notify($"Object type not implemented: {type}", NotificationType.NotImplemented);
67✔
959

960
                        return template;
38,433✔
961
                }
49,417✔
962

963
                private CadTemplate readUnlistedType(short classNumber)
964
                {
10,984✔
965
                        if (!this._classes.TryGetValue(classNumber, out DxfClass c))
10,984✔
966
                                return null;
272✔
967

968
                        CadTemplate template = null;
10,712✔
969

970
                        switch (c.DxfName)
10,712!
971
                        {
972
                                case "ACDBDICTIONARYWDFLT":
973
                                        template = this.readDictionaryWithDefault();
86✔
974
                                        break;
86✔
975
                                case "ACDBPLACEHOLDER":
976
                                        template = this.readPlaceHolder();
23✔
977
                                        break;
23✔
978
                                case "DBCOLOR":
979
                                        template = this.readDwgColor();
×
980
                                        break;
×
981
                                case "DICTIONARYVAR":
982
                                        template = this.readDictionaryVar();
1,105✔
983
                                        break;
1,105✔
984
                                case "DICTIONARYWDFLT":
985
                                        template = this.readDictionaryWithDefault();
×
986
                                        break;
×
987
                                case "GROUP":
988
                                        template = this.readGroup();
×
989
                                        break;
×
990
                                case "HATCH":
991
                                        template = this.readHatch();
44✔
992
                                        break;
44✔
993
                                case "IMAGE":
994
                                        template = this.readCadImage(new RasterImage());
77✔
995
                                        break;
77✔
996
                                case "IMAGEDEF":
997
                                        template = this.readImageDefinition();
77✔
998
                                        break;
77✔
999
                                case "IMAGEDEF_REACTOR":
1000
                                        template = this.readImageDefinitionReactor();
77✔
1001
                                        break;
77✔
1002
                                case "LAYOUT":
1003
                                        template = this.readLayout();
91✔
1004
                                        break;
91✔
1005
                                case "LWPLINE":
1006
                                case "LWPOLYLINE":
1007
                                        template = this.readLWPolyline();
121✔
1008
                                        break;
121✔
1009
                                case "MESH":
1010
                                        template = this.readMesh();
154✔
1011
                                        break;
154✔
1012
                                case "MULTILEADER":
1013
                                        template = this.readMultiLeader();
161✔
1014
                                        break;
161✔
1015
                                case "MLEADERSTYLE":
1016
                                        template = this.readMultiLeaderStyle();
172✔
1017
                                        break;
172✔
1018
                                case "PDFDEFINITION":
1019
                                        template = this.readPdfDefinition();
×
1020
                                        break;
×
1021
                                case "PDFUNDERLAY":
1022
                                        template = this.readPdfUnderlay();
×
1023
                                        break;
×
1024
                                case "SCALE":
1025
                                        template = this.readScale();
2,946✔
1026
                                        break;
2,946✔
1027
                                case "SORTENTSTABLE":
1028
                                        template = this.readSortentsTable();
154✔
1029
                                        break;
154✔
1030
                                //case "VISUALSTYLE":
1031
                                //        template = this.readVisualStyle();
1032
                                //        break;
1033
                                case "WIPEOUT":
1034
                                        template = this.readCadImage(new Wipeout());
77✔
1035
                                        break;
77✔
1036
                                case "XRECORD":
1037
                                        template = this.readXRecord();
2,115✔
1038
                                        break;
2,115✔
1039
                                default:
1040
                                        break;
3,232✔
1041
                        }
1042

1043
                        if (template == null && c.IsAnEntity)
10,712✔
1044
                        {
77✔
1045
                                template = this.readUnknownEntity(c);
77✔
1046
                                this._builder.Notify($"Unlisted object with DXF name {c.DxfName} has been read as an UnknownEntity", NotificationType.Warning);
77✔
1047
                        }
77✔
1048
                        else if (template == null && !c.IsAnEntity)
10,635✔
1049
                        {
3,249✔
1050
                                template = this.readUnknownNonGraphicalObject(c);
3,249✔
1051
                                this._builder.Notify($"Unlisted object with DXF name {c.DxfName} has been read as an UnknownNonGraphicalObject", NotificationType.Warning);
3,249✔
1052
                        }
3,249✔
1053

1054
                        if (template == null)
10,712!
1055
                        {
×
1056
                                this._builder.Notify($"Unlisted object not implemented, DXF name: {c.DxfName}", NotificationType.NotImplemented);
×
1057
                        }
×
1058

1059
                        return template;
10,712✔
1060
                }
10,984✔
1061

1062
                #region Text entities
1063

1064
                private CadTemplate readUnknownEntity(DxfClass dxfClass)
1065
                {
77✔
1066
                        UnknownEntity entity = new UnknownEntity(dxfClass);
77✔
1067
                        CadUnknownEntityTemplate template = new CadUnknownEntityTemplate(entity);
77✔
1068

1069
                        this.readCommonEntityData(template);
77✔
1070

1071
                        return template;
77✔
1072
                }
77✔
1073

1074
                private CadTemplate readUnknownNonGraphicalObject(DxfClass dxfClass)
1075
                {
3,249✔
1076
                        UnknownNonGraphicalObject obj = new UnknownNonGraphicalObject(dxfClass);
3,249✔
1077
                        CadUnknownNonGraphicalObjectTemplate template = new CadUnknownNonGraphicalObjectTemplate(obj);
3,249✔
1078

1079
                        this.readCommonNonEntityData(template);
3,249✔
1080

1081
                        return template;
3,249✔
1082
                }
3,249✔
1083

1084
                private CadTemplate readText()
1085
                {
624✔
1086
                        TextEntity text = new TextEntity();
624✔
1087
                        CadTextEntityTemplate template = new CadTextEntityTemplate(text);
624✔
1088

1089
                        this.readCommonTextData(template);
624✔
1090

1091
                        return template;
624✔
1092
                }
624✔
1093

1094
                private CadTemplate readAttribute()
1095
                {
308✔
1096
                        AttributeEntity att = new AttributeEntity();
308✔
1097
                        CadAttributeTemplate template = new CadAttributeTemplate(att);
308✔
1098

1099
                        this.readCommonTextData(template);
308✔
1100

1101
                        this.readCommonAttData(template);
308✔
1102

1103
                        return template;
308✔
1104
                }
308✔
1105

1106
                private CadTemplate readAttributeDefinition()
1107
                {
385✔
1108
                        AttributeDefinition attdef = new AttributeDefinition();
385✔
1109
                        CadAttributeTemplate template = new CadAttributeTemplate(attdef);
385✔
1110

1111
                        this.readCommonTextData(template);
385✔
1112

1113
                        this.readCommonAttData(template);
385✔
1114

1115
                        //R2010+:
1116
                        if (this.R2010Plus)
385✔
1117
                                //Version RC ?                Repeated??
1118
                                attdef.Version = this._objectReader.ReadByte();
165✔
1119

1120
                        //Common:
1121
                        //Prompt TV 3
1122
                        attdef.Prompt = this._textReader.ReadVariableText();
385✔
1123

1124
                        return template;
385✔
1125
                }
385✔
1126

1127
                private void readCommonTextData(CadTextEntityTemplate template)
1128
                {
1,317✔
1129
                        this.readCommonEntityData(template);
1,317✔
1130

1131
                        TextEntity text = (TextEntity)template.CadObject;
1,317✔
1132

1133
                        double elevation = 0.0;
1,317✔
1134
                        XY pt = new XY();
1,317✔
1135

1136
                        //R13-14 Only:
1137
                        if (this.R13_14Only)
1,317✔
1138
                        {
189✔
1139
                                //Elevation BD ---
1140
                                elevation = this._objectReader.ReadBitDouble();
189✔
1141
                                //Insertion pt 2RD 10
1142
                                pt = this._objectReader.Read2RawDouble();
189✔
1143
                                text.InsertPoint = new XYZ(pt.X, pt.Y, elevation);
189✔
1144

1145
                                //Alignment pt 2RD 11
1146
                                pt = this._objectReader.Read2RawDouble();
189✔
1147
                                text.AlignmentPoint = new XYZ(pt.X, pt.Y, elevation);
189✔
1148

1149
                                //Extrusion 3BD 210
1150
                                text.Normal = this._objectReader.Read3BitDouble();
189✔
1151
                                //Thickness BD 39
1152
                                text.Thickness = this._objectReader.ReadBitDouble();
189✔
1153
                                //Oblique ang BD 51
1154
                                text.ObliqueAngle = this._objectReader.ReadBitDouble();
189✔
1155
                                //Rotation ang BD 50
1156
                                text.Rotation = this._objectReader.ReadBitDouble();
189✔
1157
                                //Height BD 40
1158
                                text.Height = this._objectReader.ReadBitDouble();
189✔
1159
                                //Width factor BD 41
1160
                                text.WidthFactor = this._objectReader.ReadBitDouble();
189✔
1161
                                //Text value TV 1
1162
                                text.Value = this._textReader.ReadVariableText();
189✔
1163
                                //Generation BS 71
1164
                                text.Mirror = (TextMirrorFlag)this._objectReader.ReadBitShort();
189✔
1165
                                //Horiz align. BS 72
1166
                                text.HorizontalAlignment = (TextHorizontalAlignment)this._objectReader.ReadBitShort();
189✔
1167
                                //Vert align. BS 73
1168
                                text.VerticalAlignment = (TextVerticalAlignmentType)this._objectReader.ReadBitShort();
189✔
1169

1170
                                //Common:
1171
                                //Common Entity Handle Data H 7 STYLE(hard pointer)
1172
                                template.StyleHandle = this.handleReference();
189✔
1173
                                return;
189✔
1174
                        }
1175

1176
                        //DataFlags RC Used to determine presence of subsquent data
1177
                        byte dataFlags = this._objectReader.ReadByte();
1,128✔
1178

1179
                        //Elevation RD --- present if !(DataFlags & 0x01)
1180
                        if ((dataFlags & 0x1) == 0)
1,128✔
1181
                                elevation = this._objectReader.ReadDouble();
6✔
1182

1183
                        //Insertion pt 2RD 10
1184
                        pt = this._objectReader.Read2RawDouble();
1,128✔
1185
                        text.InsertPoint = new XYZ(pt.X, pt.Y, elevation);
1,128✔
1186

1187
                        //Alignment pt 2DD 11 present if !(DataFlags & 0x02), use 10 & 20 values for 2 default values.
1188
                        if ((dataFlags & 0x2) == 0)
1,128✔
1189
                        {
215✔
1190
                                double x = this._objectReader.ReadBitDoubleWithDefault((double)text.InsertPoint.X);
215✔
1191
                                double y = this._objectReader.ReadBitDoubleWithDefault((double)text.InsertPoint.Y);
215✔
1192
                                text.AlignmentPoint = new XYZ(x, y, elevation);
215✔
1193
                        }
215✔
1194

1195
                        //Extrusion BE 210
1196
                        text.Normal = this._objectReader.ReadBitExtrusion();
1,128✔
1197
                        //Thickness BT 39
1198
                        text.Thickness = this._objectReader.ReadBitThickness();
1,128✔
1199

1200
                        //Oblique ang RD 51 present if !(DataFlags & 0x04)
1201
                        if ((dataFlags & 0x4) == 0)
1,128✔
1202
                                text.ObliqueAngle = this._objectReader.ReadDouble();
6✔
1203
                        //Rotation ang RD 50 present if !(DataFlags & 0x08)
1204
                        if ((dataFlags & 0x8) == 0)
1,128✔
1205
                                text.Rotation = this._objectReader.ReadDouble();
6✔
1206
                        //Height RD 40
1207
                        text.Height = this._objectReader.ReadDouble();
1,128✔
1208
                        //Width factor RD 41 present if !(DataFlags & 0x10)
1209
                        if ((dataFlags & 0x10) == 0)
1,128✔
1210
                                text.WidthFactor = this._objectReader.ReadDouble();
6✔
1211

1212
                        //Text value TV 1
1213
                        text.Value = this._textReader.ReadVariableText();
1,128✔
1214

1215
                        //Generation BS 71 present if !(DataFlags & 0x20)
1216
                        if ((dataFlags & 0x20) == 0)
1,128!
1217
                                text.Mirror = (TextMirrorFlag)this._objectReader.ReadBitShort();
×
1218
                        //Horiz align. BS 72 present if !(DataFlags & 0x40)
1219
                        if ((dataFlags & 0x40) == 0)
1,128!
1220
                                text.HorizontalAlignment = (TextHorizontalAlignment)this._objectReader.ReadBitShort();
×
1221
                        //Vert align. BS 73 present if !(DataFlags & 0x80)
1222
                        if ((dataFlags & 0x80) == 0)
1,128✔
1223
                                text.VerticalAlignment = (TextVerticalAlignmentType)this._objectReader.ReadBitShort();
209✔
1224

1225
                        //Common:
1226
                        //Common Entity Handle Data H 7 STYLE(hard pointer)
1227
                        template.StyleHandle = this.handleReference();
1,128✔
1228
                }
1,317✔
1229

1230
                private void readCommonAttData(CadAttributeTemplate template)
1231
                {
693✔
1232
                        AttributeBase att = template.CadObject as AttributeBase;
693✔
1233

1234
                        //R2010+:
1235
                        if (this.R2010Plus)
693✔
1236
                        {
297✔
1237
                                //Version RC ?
1238
                                att.Version = this._objectReader.ReadByte();
297✔
1239
                        }
297✔
1240

1241
                        //R2018+:
1242
                        if (this.R2018Plus)
693✔
1243
                        {
99✔
1244
                                att.AttributeType = (AttributeType)this._objectReader.ReadByte();
99✔
1245
                        }
99✔
1246

1247
                        switch (att.AttributeType)
693✔
1248
                        {
1249
                                case AttributeType.MultiLine:
1250
                                case AttributeType.ConstantMultiLine:
1251
                                        //Attribute type is multi line
1252
                                        //MTEXT fields … Here all fields of an embedded MTEXT object
1253
                                        //are written, starting from the Entmode
1254
                                        //(entity mode). The owner handle can be 0.
1255
                                        att.MText = new MText();
22✔
1256
                                        CadTextEntityTemplate mtextTemplate = new CadTextEntityTemplate(att.MText);
22✔
1257
                                        template.MTextTemplate = mtextTemplate;
22✔
1258

1259
                                        this.readEntityMode(mtextTemplate);
22✔
1260

1261
                                        this.readMText(mtextTemplate, false);
22✔
1262

1263
                                        short dataSize = this._objectReader.ReadBitShort();
22✔
1264
                                        if (dataSize > 0)
22!
1265
                                        {
×
1266
                                                //Annotative data bytes RC Byte array with length Annotative data size.
1267
                                                var data = this._objectReader.ReadBytes(dataSize);
×
1268
                                                //Registered application H Hard pointer.
1269
                                                var appHanlde = this.handleReference(); //What to do??
×
1270
                                                                                                                                //Unknown BS 72? Value 0.
1271
                                                this._objectReader.ReadBitShort();
×
1272
                                        }
×
1273
                                        break;
22✔
1274
                        }
1275

1276
                        //Common:
1277
                        //Tag TV 2
1278
                        att.Tag = this._textReader.ReadVariableText();
693✔
1279
                        //Field length BS 73 unused
1280
                        short length = this._objectReader.ReadBitShort();
693✔
1281
                        //Flags RC 70 NOT bit-pair - coded.
1282
                        att.Flags = (AttributeFlags)this._objectReader.ReadByte();
693✔
1283
                        //R2007 +:
1284
                        if (this.R2007Plus)
693✔
1285
                        {
396✔
1286
                                //Lock position flag B 280
1287
                                att.IsReallyLocked = this._objectReader.ReadBit();
396✔
1288
                        }
396✔
1289
                }
693✔
1290

1291
                #endregion Text entities
1292

1293
                private CadTemplate readDocumentTable<T>(Table<T> table, CadTableTemplate<T> template = null)
1294
                        where T : TableEntry
1295
                {
1,026✔
1296
                        if (template == null)
1,026✔
1297
                                template = new CadTableTemplate<T>(table);
798✔
1298

1299
                        this.readCommonNonEntityData(template);
1,026✔
1300

1301
                        //Common:
1302
                        //Numentries BL 70
1303
                        //Blocks:         Numentries BL 70 Doesn't count *MODEL_SPACE and *PAPER_SPACE
1304
                        //Layers:         Numentries BL 70 Counts layer "0", too
1305
                        int numentries = this._objectReader.ReadBitLong();
1,026✔
1306
                        for (int i = 0; i < numentries; ++i)
13,616✔
1307
                                //numentries handles in the file (soft owner)
1308
                                template.EntryHandles.Add(this.handleReference());
5,782✔
1309

1310
                        return template;
1,026✔
1311
                }
1,026✔
1312

1313
                private CadTemplate readBlock()
1314
                {
1,323✔
1315
                        Block block = new Block(new BlockRecord());
1,323✔
1316
                        CadEntityTemplate template = new CadEntityTemplate(block);
1,323✔
1317

1318
                        this.readCommonEntityData(template);
1,323✔
1319

1320
                        //Block name TV 2
1321
                        string name = this._textReader.ReadVariableText();
1,323✔
1322
                        if (!name.IsNullOrEmpty())
1,323✔
1323
                        {
1,323✔
1324
                                block.Name = name;
1,323✔
1325
                        }
1,323✔
1326

1327
                        return template;
1,323✔
1328
                }
1,323✔
1329

1330
                private CadTemplate readEndBlock()
1331
                {
1,323✔
1332
                        BlockEnd block = new BlockEnd(new BlockRecord());
1,323✔
1333
                        CadEntityTemplate template = new CadEntityTemplate(block);
1,323✔
1334

1335
                        this.readCommonEntityData(template);
1,323✔
1336

1337
                        return template;
1,323✔
1338
                }
1,323✔
1339

1340
                private CadTemplate readSeqend()
1341
                {
308✔
1342
                        CadEntityTemplate template = new CadEntityTemplate(new Seqend());
308✔
1343

1344
                        this.readCommonEntityData(template);
308✔
1345

1346
                        return template;
308✔
1347
                }
308✔
1348

1349
                #region Insert methods
1350

1351
                private CadTemplate readInsert()
1352
                {
385✔
1353
                        CadInsertTemplate template = new CadInsertTemplate(new Insert());
385✔
1354

1355
                        this.readInsertCommonData(template);
385✔
1356
                        this.readInsertCommonHandles(template);
385✔
1357

1358
                        return template;
385✔
1359
                }
385✔
1360

1361
                private CadTemplate readMInsert()
1362
                {
8✔
1363
                        Insert insert = new Insert();
8✔
1364
                        CadInsertTemplate template = new CadInsertTemplate(insert);
8✔
1365

1366
                        this.readInsertCommonData(template);
8✔
1367

1368
                        //Common:
1369
                        //Numcols BS 70
1370
                        insert.ColumnCount = (ushort)this._objectReader.ReadBitShort();
8✔
1371
                        //Numrows BS 71
1372
                        insert.RowCount = (ushort)this._objectReader.ReadBitShort();
8✔
1373
                        //Col spacing BD 44
1374
                        insert.ColumnSpacing = this._objectReader.ReadBitDouble();
8✔
1375
                        //Row spacing BD 45
1376
                        insert.RowSpacing = this._objectReader.ReadBitDouble();
8✔
1377

1378
                        this.readInsertCommonHandles(template);
8✔
1379

1380
                        return template;
8✔
1381
                }
8✔
1382

1383
                private void readInsertCommonData(CadInsertTemplate template)
1384
                {
393✔
1385
                        Insert insert = template.CadObject as Insert;
393✔
1386

1387
                        this.readCommonEntityData(template);
393✔
1388

1389
                        //Ins pt 3BD 10
1390
                        insert.InsertPoint = this._objectReader.Read3BitDouble();
393✔
1391

1392
                        //R13-R14 Only:
1393
                        if (this.R13_14Only)
393✔
1394
                        {
57✔
1395
                                XYZ scale = this._objectReader.Read3BitDouble();
57✔
1396
                                //X Scale BD 41
1397
                                insert.XScale = scale.X;
57✔
1398
                                //Y Scale BD 42
1399
                                insert.YScale = scale.Y;
57✔
1400
                                //Z Scale BD 43
1401
                                insert.ZScale = scale.Z;
57✔
1402
                        }
57✔
1403

1404
                        //R2000 + Only:
1405
                        if (this.R2000Plus)
393✔
1406
                        {
336✔
1407
                                //Data flags BB
1408
                                //Scale Data Varies with Data flags:
1409
                                switch (this._objectReader.Read2Bits())
336!
1410
                                {
1411
                                        //00 – 41 value stored as a RD, followed by a 42 value stored as DD (use 41 for default value), and a 43 value stored as a DD(use 41 value for default value).
1412
                                        case 0:
1413
                                                insert.XScale = this._objectReader.ReadDouble();
6✔
1414
                                                insert.YScale = this._objectReader.ReadBitDoubleWithDefault(insert.XScale);
6✔
1415
                                                insert.ZScale = this._objectReader.ReadBitDoubleWithDefault(insert.XScale);
6✔
1416
                                                break;
6✔
1417
                                        //01 – 41 value is 1.0, 2 DD’s are present, each using 1.0 as the default value, representing the 42 and 43 values.
1418
                                        case 1:
1419
                                                insert.YScale = this._objectReader.ReadBitDoubleWithDefault(insert.XScale);
×
1420
                                                insert.ZScale = this._objectReader.ReadBitDoubleWithDefault(insert.XScale);
×
1421
                                                break;
×
1422
                                        //10 – 41 value stored as a RD, and 42 & 43 values are not stored, assumed equal to 41 value.
1423
                                        case 2:
1424
                                                double xyz = this._objectReader.ReadDouble();
330✔
1425
                                                insert.XScale = xyz;
330✔
1426
                                                insert.YScale = xyz;
330✔
1427
                                                insert.ZScale = xyz;
330✔
1428
                                                break;
330✔
1429
                                        //11 - scale is (1.0, 1.0, 1.0), no data stored.
1430
                                        case 3:
1431
                                                insert.XScale = 1;
×
1432
                                                insert.YScale = 1;
×
1433
                                                insert.ZScale = 1;
×
1434
                                                break;
×
1435
                                }
1436
                        }
336✔
1437

1438
                        //Common:
1439
                        //Rotation BD 50
1440
                        insert.Rotation = this._objectReader.ReadBitDouble();
393✔
1441
                        //Extrusion 3BD 210
1442
                        insert.Normal = this._objectReader.Read3BitDouble();
393✔
1443
                        //Has ATTRIBs B 66 Single bit; 1 if ATTRIBs follow.
1444
                        template.HasAtts = this._objectReader.ReadBit();
393✔
1445
                        template.OwnedObjectsCount = 0;
393✔
1446

1447
                        //R2004+:
1448
                        if (this.R2004Plus && template.HasAtts)
393✔
1449
                                //Owned Object Count BL Number of objects owned by this object.
1450
                                template.OwnedObjectsCount = this._objectReader.ReadBitLong();
110✔
1451
                }
393✔
1452

1453
                private void readInsertCommonHandles(CadInsertTemplate template)
1454
                {
393✔
1455
                        //Common:
1456
                        //Common Entity Handle Data
1457
                        //H 2 BLOCK HEADER(hard pointer)
1458
                        template.BlockHeaderHandle = this.handleReference();
393✔
1459

1460
                        if (!template.HasAtts)
393✔
1461
                                return;
239✔
1462

1463
                        //R13 - R2000:
1464
                        if (this._version >= ACadVersion.AC1012 && this._version <= ACadVersion.AC1015)
154!
1465
                        {
44✔
1466
                                //H[1st ATTRIB(soft pointer)] if 66 bit set; can be NULL
1467
                                template.FirstAttributeHandle = this.handleReference();
44✔
1468
                                //H[last ATTRIB](soft pointer)] if 66 bit set; can be NULL
1469
                                template.EndAttributeHandle = this.handleReference();
44✔
1470
                        }
44✔
1471
                        //R2004+:
1472
                        else if (this.R2004Plus)
110✔
1473
                        {
110✔
1474
                                for (int i = 0; i < template.OwnedObjectsCount; ++i)
660✔
1475
                                        //H[ATTRIB(hard owner)] Repeats “Owned Object Count” times.
1476
                                        template.AttributesHandles.Add(this.handleReference());
220✔
1477
                        }
110✔
1478

1479
                        //Common:
1480
                        //H[SEQEND(hard owner)] if 66 bit set
1481
                        template.SeqendHandle = this.handleReference();
154✔
1482
                }
393✔
1483

1484
                #endregion Insert methods
1485

1486
                private CadTemplate readVertex2D()
1487
                {
×
1488
                        Vertex2D vertex = new Vertex2D();
×
1489
                        CadEntityTemplate template = new CadEntityTemplate(vertex);
×
1490

1491
                        this.readCommonEntityData(template);
×
1492

1493
                        //Flags EC 70 NOT bit-pair-coded.
1494
                        vertex.Flags = (VertexFlags)this._objectReader.ReadByte();
×
1495
                        //Point 3BD 10 NOTE THAT THE Z SEEMS TO ALWAYS BE 0.0! The Z must be taken from the 2D POLYLINE elevation.
1496
                        vertex.Location = this._objectReader.Read3BitDouble();
×
1497

1498
                        //Start width BD 40 If it's negative, use the abs val for start AND end widths (and note that no end width will be present).
1499
                        //This is a compression trick for cases where the start and end widths are identical and non-0.
1500
                        double width = this._objectReader.ReadBitDouble();
×
1501
                        if (width < 0.0)
×
1502
                        {
×
1503
                                vertex.StartWidth = -width;
×
1504
                                vertex.EndWidth = -width;
×
1505
                        }
×
1506
                        else
1507
                        {
×
1508
                                vertex.StartWidth = width;
×
1509
                                //End width BD 41 Not present if the start width is < 0.0; see above.
1510
                                vertex.EndWidth = this._objectReader.ReadBitDouble();
×
1511
                        }
×
1512

1513
                        //Bulge BD 42
1514
                        vertex.Bulge = this._objectReader.ReadBitDouble();
×
1515

1516
                        //R2010+:
1517
                        if (this.R2010Plus)
×
1518
                                //Vertex ID BL 91
1519
                                vertex.Id = this._objectReader.ReadBitLong();
×
1520

1521
                        //Common:
1522
                        //Tangent dir BD 50
1523
                        vertex.CurveTangent = this._objectReader.ReadBitDouble();
×
1524

1525
                        return template;
×
1526
                }
×
1527

1528
                private CadTemplate readVertex3D(Vertex vertex)
1529
                {
770✔
1530
                        CadEntityTemplate template = new CadEntityTemplate(vertex);
770✔
1531

1532
                        this.readCommonEntityData(template);
770✔
1533

1534
                        //Flags EC 70 NOT bit-pair-coded.
1535
                        vertex.Flags = (VertexFlags)this._objectReader.ReadByte();
770✔
1536
                        //Point 3BD 10
1537
                        vertex.Location = this._objectReader.Read3BitDouble();
770✔
1538

1539
                        return template;
770✔
1540
                }
770✔
1541

1542
                private CadTemplate readPfaceVertex()
1543
                {
154✔
1544
                        VertexFaceRecord face = new VertexFaceRecord();
154✔
1545
                        CadEntityTemplate template = new CadEntityTemplate(face);
154✔
1546

1547
                        this.readCommonEntityData(template);
154✔
1548

1549
                        //Vert index BS 71 1 - based vertex index(see DXF doc)
1550
                        face.Index1 = this._objectReader.ReadBitShort();
154✔
1551
                        //Vert index BS 72 1 - based vertex index(see DXF doc)
1552
                        face.Index2 = this._objectReader.ReadBitShort();
154✔
1553
                        //Vert index BS 73 1 - based vertex index(see DXF doc)
1554
                        face.Index3 = this._objectReader.ReadBitShort();
154✔
1555
                        //Vert index BS 74 1 - based vertex index(see DXF doc)
1556
                        face.Index4 = this._objectReader.ReadBitShort();
154✔
1557

1558
                        return template;
154✔
1559
                }
154✔
1560

1561
                private CadTemplate readPolyline2D()
1562
                {
×
1563
                        Polyline2D pline = new Polyline2D();
×
1564
                        CadPolyLineTemplate template = new CadPolyLineTemplate(pline);
×
1565

1566
                        this.readCommonEntityData(template);
×
1567

1568
                        //Flags BS 70
1569
                        pline.Flags = (PolylineFlags)this._objectReader.ReadBitShort();
×
1570
                        //Curve type BS 75 Curve and smooth surface type.
1571
                        pline.SmoothSurface = (SmoothSurfaceType)this._objectReader.ReadBitShort();
×
1572
                        //Start width BD 40 Default start width
1573
                        pline.StartWidth = this._objectReader.ReadBitDouble();
×
1574
                        //End width BD 41 Default end width
1575
                        pline.EndWidth = this._objectReader.ReadBitDouble();
×
1576
                        //Thickness BT 39
1577
                        pline.Thickness = this._objectReader.ReadBitThickness();
×
1578
                        //Elevation BD 10 The 10-pt is (0,0,elev)
1579
                        pline.Elevation = this._objectReader.ReadBitDouble();
×
1580
                        //Extrusion BE 210
1581
                        pline.Normal = this._objectReader.ReadBitExtrusion();
×
1582

1583
                        //R2004+:
1584
                        if (this.R2004Plus)
×
1585
                        {
×
1586
                                //Owned Object Count BL Number of objects owned by this object.
1587
                                int nownedObjects = this._objectReader.ReadBitLong();
×
1588

1589
                                for (int i = 0; i < nownedObjects; ++i)
×
1590
                                        template.VertexHandles.Add(this.handleReference());
×
1591
                        }
×
1592

1593
                        //R13-R2000:
1594
                        if (this._version >= ACadVersion.AC1012 && this._version <= ACadVersion.AC1015)
×
1595
                        {
×
1596
                                //H first VERTEX (soft pointer)
1597
                                template.FirstVertexHandle = this.handleReference();
×
1598
                                //H last VERTEX (soft pointer)
1599
                                template.LastVertexHandle = this.handleReference();
×
1600
                        }
×
1601

1602
                        //Common:
1603
                        //H SEQEND(hard owner)
1604
                        template.SeqendHandle = this.handleReference();
×
1605

1606
                        return template;
×
1607
                }
×
1608

1609
                private CadTemplate readPolyline3D()
1610
                {
77✔
1611
                        Polyline3D pline = new Polyline3D();
77✔
1612
                        CadPolyLineTemplate template = new CadPolyLineTemplate(pline);
77✔
1613

1614
                        this.readCommonEntityData(template);
77✔
1615

1616
                        //Flags RC 70 NOT DIRECTLY THE 75. Bit-coded (76543210):
1617
                        byte flags = this._objectReader.ReadByte();
77✔
1618

1619
                        //75 0 : Splined(75 value is 5)
1620
                        //1 : Splined(75 value is 6)
1621
                        bool splined = ((uint)flags & 0b1) > 0;
77✔
1622
                        //Should assign pline.SmoothSurface ??
1623

1624
                        //(If either is set, set 70 bit 2(4) to indicate splined.)
1625
                        bool splined1 = ((uint)flags & 0b10) > 0;
77✔
1626

1627
                        if (splined | splined1)
77!
1628
                        {
×
1629
                                pline.Flags |= PolylineFlags.SplineFit;
×
1630
                        }
×
1631

1632
                        //Flags RC 70 NOT DIRECTLY THE 70. Bit-coded (76543210):
1633
                        //0 : Closed(70 bit 0(1))
1634
                        //(Set 70 bit 3(8) because this is a 3D POLYLINE.)
1635
                        pline.Flags |= PolylineFlags.Polyline3D;
77✔
1636
                        if ((this._objectReader.ReadByte() & 1U) > 0U)
77!
1637
                        {
×
1638
                                pline.Flags |= PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM;
×
1639
                        }
×
1640

1641
                        //R2004+:
1642
                        if (this.R2004Plus)
77✔
1643
                        {
55✔
1644
                                //Owned Object Count BL Number of objects owned by this object.
1645
                                int nownedObjects = this._objectReader.ReadBitLong();
55✔
1646

1647
                                for (int i = 0; i < nownedObjects; ++i)
660✔
1648
                                        template.VertexHandles.Add(this.handleReference());
275✔
1649
                        }
55✔
1650

1651
                        //R13-R2000:
1652
                        if (this._version >= ACadVersion.AC1012 && this._version <= ACadVersion.AC1015)
77!
1653
                        {
22✔
1654
                                //H first VERTEX (soft pointer)
1655
                                template.FirstVertexHandle = this.handleReference();
22✔
1656
                                //H last VERTEX (soft pointer)
1657
                                template.LastVertexHandle = this.handleReference();
22✔
1658
                        }
22✔
1659

1660
                        //Common:
1661
                        //H SEQEND(hard owner)
1662
                        template.SeqendHandle = this.handleReference();
77✔
1663

1664
                        return template;
77✔
1665
                }
77✔
1666

1667
                private CadTemplate readArc()
1668
                {
239✔
1669
                        Arc arc = new Arc();
239✔
1670
                        CadEntityTemplate template = new CadArcTemplate(arc);
239✔
1671

1672
                        this.readCommonEntityData(template);
239✔
1673

1674
                        //Center 3BD 10
1675
                        arc.Center = this._objectReader.Read3BitDouble();
239✔
1676
                        //Radius BD 40
1677
                        arc.Radius = this._objectReader.ReadBitDouble();
239✔
1678
                        //Thickness BT 39
1679
                        arc.Thickness = this._objectReader.ReadBitThickness();
239✔
1680
                        //Extrusion BE 210
1681
                        arc.Normal = this._objectReader.ReadBitExtrusion();
239✔
1682
                        //Start angle BD 50
1683
                        arc.StartAngle = this._objectReader.ReadBitDouble();
239✔
1684
                        //End angle BD 51
1685
                        arc.EndAngle = this._objectReader.ReadBitDouble();
239✔
1686

1687
                        return template;
239✔
1688
                }
239✔
1689

1690
                private CadTemplate readCircle()
1691
                {
316✔
1692
                        Circle circle = new Circle();
316✔
1693
                        CadEntityTemplate template = new CadEntityTemplate(circle);
316✔
1694

1695
                        this.readCommonEntityData(template);
316✔
1696

1697
                        //Center 3BD 10
1698
                        circle.Center = this._objectReader.Read3BitDouble();
316✔
1699
                        //Radius BD 40
1700
                        circle.Radius = this._objectReader.ReadBitDouble();
316✔
1701
                        //Thickness BT 39
1702
                        circle.Thickness = this._objectReader.ReadBitThickness();
316✔
1703
                        //Extrusion BE 210
1704
                        circle.Normal = this._objectReader.ReadBitExtrusion();
316✔
1705

1706
                        return template;
316✔
1707
                }
316✔
1708

1709
                private CadTemplate readLine()
1710
                {
4,944✔
1711
                        Line line = new Line();
4,944✔
1712
                        CadEntityTemplate template = new CadEntityTemplate(line);
4,944✔
1713

1714
                        this.readCommonEntityData(template);
4,944✔
1715

1716
                        //R13-R14 Only:
1717
                        if (this.R13_14Only)
4,944✔
1718
                        {
707✔
1719
                                //Start pt 3BD 10
1720
                                line.StartPoint = this._objectReader.Read3BitDouble();
707✔
1721
                                //End pt 3BD 11
1722
                                line.EndPoint = this._objectReader.Read3BitDouble();
707✔
1723
                        }
707✔
1724

1725
                        //R2000+:
1726
                        if (this.R2000Plus)
4,944✔
1727
                        {
4,237✔
1728
                                //Z’s are zero bit B
1729
                                bool flag = this._objectReader.ReadBit();
4,237✔
1730
                                //Start Point x RD 10
1731
                                double startX = this._objectReader.ReadDouble();
4,237✔
1732
                                //End Point x DD 11 Use 10 value for default
1733
                                double endX = this._objectReader.ReadBitDoubleWithDefault(startX);
4,237✔
1734
                                //Start Point y RD 20
1735
                                double startY = this._objectReader.ReadDouble();
4,237✔
1736
                                //End Point y DD 21 Use 20 value for default
1737
                                double endY = this._objectReader.ReadBitDoubleWithDefault(startY);
4,237✔
1738

1739
                                double startZ = 0.0;
4,237✔
1740
                                double endZ = 0.0;
4,237✔
1741

1742
                                if (!flag)
4,237✔
1743
                                {
11✔
1744
                                        //Start Point z RD 30 Present only if “Z’s are zero bit” is 0
1745
                                        startZ = this._objectReader.ReadDouble();
11✔
1746
                                        //End Point z DD 31 Present only if “Z’s are zero bit” is 0, use 30 value for default.
1747
                                        endZ = this._objectReader.ReadBitDoubleWithDefault(startZ);
11✔
1748
                                }
11✔
1749

1750
                                line.StartPoint = new XYZ(startX, startY, startZ);
4,237✔
1751
                                line.EndPoint = new XYZ(endX, endY, endZ);
4,237✔
1752
                        }
4,237✔
1753

1754
                        //Common:
1755
                        //Thickness BT 39
1756
                        line.Thickness = this._objectReader.ReadBitThickness();
4,944✔
1757
                        //Extrusion BE 210
1758
                        line.Normal = this._objectReader.ReadBitExtrusion();
4,944✔
1759

1760
                        return template;
4,944✔
1761
                }
4,944✔
1762

1763
                #region Dimensions
1764

1765
                private CadTemplate readDimOrdinate()
1766
                {
162✔
1767
                        DimensionOrdinate dimension = new DimensionOrdinate();
162✔
1768
                        CadDimensionTemplate template = new CadDimensionTemplate(dimension);
162✔
1769

1770
                        this.readCommonDimensionData(template);
162✔
1771

1772
                        //Common:
1773
                        //10 - pt 3BD 10 See DXF documentation.
1774
                        dimension.DefinitionPoint = this._objectReader.Read3BitDouble();
162✔
1775
                        //13 - pt 3BD 13 See DXF documentation.
1776
                        dimension.FeatureLocation = this._objectReader.Read3BitDouble();
162✔
1777
                        //14 - pt 3BD 14 See DXF documentation.
1778
                        dimension.LeaderEndpoint = this._objectReader.Read3BitDouble();
162✔
1779

1780
                        byte flags = this._objectReader.ReadByte();
162✔
1781
                        dimension.IsOrdinateTypeX = (flags & 0b01) != 0;
162✔
1782

1783
                        this.readCommonDimensionHandles(template);
162✔
1784

1785
                        return template;
162✔
1786
                }
162✔
1787

1788
                private CadTemplate readDimLinear()
1789
                {
85✔
1790
                        DimensionLinear dimension = new DimensionLinear();
85✔
1791
                        CadDimensionTemplate template = new CadDimensionTemplate(dimension);
85✔
1792

1793
                        this.readCommonDimensionData(template);
85✔
1794

1795
                        this.readCommonDimensionAlignedData(template);
85✔
1796

1797
                        //Dim rot BD 50 Linear dimension rotation; see DXF documentation.
1798
                        dimension.Rotation = this._objectReader.ReadBitDouble();
85✔
1799

1800
                        this.readCommonDimensionHandles(template);
85✔
1801

1802
                        return template;
85✔
1803
                }
85✔
1804

1805
                private CadTemplate readDimAligned()
1806
                {
85✔
1807
                        DimensionLinear dimension = new DimensionLinear();
85✔
1808
                        CadDimensionTemplate template = new CadDimensionTemplate(dimension);
85✔
1809

1810
                        this.readCommonDimensionData(template);
85✔
1811

1812
                        this.readCommonDimensionAlignedData(template);
85✔
1813

1814
                        this.readCommonDimensionHandles(template);
85✔
1815

1816
                        return template;
85✔
1817
                }
85✔
1818

1819
                private CadTemplate readDimAngular3pt()
1820
                {
85✔
1821
                        DimensionAngular3Pt dimension = new DimensionAngular3Pt();
85✔
1822
                        CadDimensionTemplate template = new CadDimensionTemplate(dimension);
85✔
1823

1824
                        this.readCommonDimensionData(template);
85✔
1825

1826
                        //Common:
1827
                        //10 - pt 3BD 10 See DXF documentation.
1828
                        dimension.DefinitionPoint = this._objectReader.Read3BitDouble();
85✔
1829
                        //13 - pt 3BD 13 See DXF documentation.
1830
                        dimension.FirstPoint = this._objectReader.Read3BitDouble();
85✔
1831
                        //14 - pt 3BD 14 See DXF documentation.
1832
                        dimension.SecondPoint = this._objectReader.Read3BitDouble();
85✔
1833
                        //15-pt 3BD 15 See DXF documentation.
1834
                        dimension.AngleVertex = this._objectReader.Read3BitDouble();
85✔
1835

1836
                        this.readCommonDimensionHandles(template);
85✔
1837

1838
                        return template;
85✔
1839
                }
85✔
1840

1841
                private CadTemplate readDimLine2pt()
1842
                {
85✔
1843
                        DimensionAngular2Line dimension = new DimensionAngular2Line();
85✔
1844
                        CadDimensionTemplate template = new CadDimensionTemplate(dimension);
85✔
1845

1846
                        this.readCommonDimensionData(template);
85✔
1847

1848
                        //Common:
1849
                        //16-pt 2RD 16 See DXF documentation.
1850
                        XY xy = this._objectReader.Read2RawDouble();
85✔
1851
                        dimension.DimensionArc = new XYZ(xy.X, xy.Y, dimension.TextMiddlePoint.Z);
85✔
1852

1853
                        //13 - pt 3BD 13 See DXF documentation.
1854
                        dimension.FirstPoint = this._objectReader.Read3BitDouble();
85✔
1855
                        //14 - pt 3BD 14 See DXF documentation.
1856
                        dimension.SecondPoint = this._objectReader.Read3BitDouble();
85✔
1857
                        //15-pt 3BD 15 See DXF documentation.
1858
                        dimension.AngleVertex = this._objectReader.Read3BitDouble();
85✔
1859
                        //10 - pt 3BD 10 See DXF documentation.
1860
                        dimension.DefinitionPoint = this._objectReader.Read3BitDouble();
85✔
1861

1862
                        this.readCommonDimensionHandles(template);
85✔
1863

1864
                        return template;
85✔
1865
                }
85✔
1866

1867
                private CadTemplate readDimRadius()
1868
                {
85✔
1869
                        DimensionRadius dimension = new DimensionRadius();
85✔
1870
                        CadDimensionTemplate template = new CadDimensionTemplate(dimension);
85✔
1871

1872
                        this.readCommonDimensionData(template);
85✔
1873

1874
                        //Common:
1875
                        //10 - pt 3BD 10 See DXF documentation.
1876
                        dimension.DefinitionPoint = this._objectReader.Read3BitDouble();
85✔
1877
                        //15-pt 3BD 15 See DXF documentation.
1878
                        dimension.AngleVertex = this._objectReader.Read3BitDouble();
85✔
1879
                        //Leader len D 40 Leader length.
1880
                        dimension.LeaderLength = this._objectReader.ReadBitDouble();
85✔
1881

1882
                        this.readCommonDimensionHandles(template);
85✔
1883

1884
                        return template;
85✔
1885
                }
85✔
1886

1887
                private CadTemplate readDimDiameter()
1888
                {
85✔
1889
                        DimensionDiameter dimension = new DimensionDiameter();
85✔
1890
                        CadDimensionTemplate template = new CadDimensionTemplate(dimension);
85✔
1891

1892
                        this.readCommonDimensionData(template);
85✔
1893

1894
                        //Common:
1895
                        //10 - pt 3BD 10 See DXF documentation.
1896
                        dimension.DefinitionPoint = this._objectReader.Read3BitDouble();
85✔
1897
                        //15-pt 3BD 15 See DXF documentation.
1898
                        dimension.AngleVertex = this._objectReader.Read3BitDouble();
85✔
1899
                        //Leader len D 40 Leader length.
1900
                        dimension.LeaderLength = this._objectReader.ReadBitDouble();
85✔
1901

1902
                        this.readCommonDimensionHandles(template);
85✔
1903

1904
                        return template;
85✔
1905
                }
85✔
1906

1907
                private void readCommonDimensionData(CadDimensionTemplate template)
1908
                {
672✔
1909
                        this.readCommonEntityData(template);
672✔
1910

1911
                        Dimension dimension = template.CadObject as Dimension;
672✔
1912

1913
                        //R2010:
1914
                        if (this.R2010Plus)
672✔
1915
                                //Version RC 280 0 = R2010
1916
                                dimension.Version = this._objectReader.ReadByte();
285✔
1917

1918
                        //Common:
1919
                        //Extrusion 3BD 210
1920
                        dimension.Normal = this._objectReader.Read3BitDouble();
672✔
1921
                        //Text midpt 2RD 11 See DXF documentation.
1922
                        XY midpt = this._objectReader.Read2RawDouble();
672✔
1923
                        //Elevation BD 11 Z - coord for the ECS points(11, 12, 16).
1924
                        //12 (The 16 remains (0,0,0) in entgets of this entity,
1925
                        //since the 16 is not used in this type of dimension
1926
                        //and is not present in the binary form here.)
1927
                        double elevation = this._objectReader.ReadBitDouble();
672✔
1928
                        dimension.TextMiddlePoint = new XYZ(midpt.X, midpt.Y, elevation);
672✔
1929

1930
                        //Flags 1 RC 70 Non - bit - pair - coded.
1931
                        //NOT the 70 group, but helps define it.
1932
                        //Apparently only the two lowest bit are used:
1933
                        //76543210:
1934
                        //Bit 0 : The OPPOSITE of bit 7(128) of 70.
1935
                        //Bit 1 : Same as bit 5(32) of the 70(but 32 is not doc'd by ACAD).
1936
                        //The actual 70 - group value comes from 3 things:
1937
                        //6 for being an ordinate DIMENSION, plus whatever bits "Flags 1" and "Flags 2" specify.
1938

1939
                        byte flags = this._objectReader.ReadByte();
672✔
1940
                        dimension.IsTextUserDefinedLocation = (flags & 0b01) == 0;
672✔
1941

1942
                        //User text TV 1
1943
                        dimension.Text = this._textReader.ReadVariableText();
672✔
1944

1945
                        //Text rot BD 53 See DXF documentation.
1946
                        dimension.TextRotation = this._objectReader.ReadBitDouble();
672✔
1947
                        //Horiz dir BD 51 See DXF documentation.
1948
                        dimension.HorizontalDirection = this._objectReader.ReadBitDouble();
672✔
1949

1950
                        ///<see cref="DwgObjectWriter.writeCommonDimensionData"></see>
1951
                        //TODO: readDimension insert scale and rotation not implemented
1952

1953
                        //Ins X - scale BD 41 Undoc'd. These apply to the insertion of the
1954
                        //Ins Y - scale BD 42 anonymous block. None of them can be
1955
                        //Ins Z - scale BD 43 dealt with via entget/entmake/entmod.
1956
                        var insertionScaleFactor = new XYZ(this._objectReader.ReadBitDouble(), this._objectReader.ReadBitDouble(), this._objectReader.ReadBitDouble());
672✔
1957

1958
                        //Ins rotation BD 54 The last 2(43 and 54) are reported by DXFOUT(when not default values).
1959
                        //ALL OF THEM can be set via DXFIN, however.
1960
                        var insertionRotation = this._objectReader.ReadBitDouble();
672✔
1961

1962
                        //R2000 +:
1963
                        if (this.R2000Plus)
672✔
1964
                        {
570✔
1965
                                //Attachment Point BS 71
1966
                                dimension.AttachmentPoint = (AttachmentPointType)this._objectReader.ReadBitShort();
570✔
1967
                                //Linespacing Style BS 72
1968
                                dimension.LineSpacingStyle = (LineSpacingStyleType)this._objectReader.ReadBitShort();
570✔
1969
                                //Linespacing Factor BD 41
1970
                                dimension.LineSpacingFactor = this._objectReader.ReadBitDouble();
570✔
1971
                                //Actual Measurement BD 42
1972
                                this._objectReader.ReadBitDouble();
570✔
1973
                        }
570✔
1974

1975
                        //R2007 +:
1976
                        if (this.R2007Plus)
672✔
1977
                        {
380✔
1978
                                //Unknown B 73
1979
                                this._objectReader.ReadBit();
380✔
1980
                                //Flip arrow1 B 74
1981
                                dimension.FlipArrow1 = this._objectReader.ReadBit();
380✔
1982
                                //Flip arrow2 B 75
1983
                                dimension.FlipArrow2 = this._objectReader.ReadBit();
380✔
1984
                        }
380✔
1985

1986
                        //Common:
1987
                        //12 - pt 2RD 12 See DXF documentation.
1988
                        XY pt = this._objectReader.Read2RawDouble();
672✔
1989
                        dimension.InsertionPoint = new XYZ((double)pt.X, (double)pt.Y, elevation);
672✔
1990
                }
672✔
1991

1992
                private void readCommonDimensionAlignedData(CadDimensionTemplate template)
1993
                {
170✔
1994
                        DimensionAligned dimension = (DimensionAligned)template.CadObject;
170✔
1995

1996
                        //Common:
1997
                        //13 - pt 3BD 13 See DXF documentation.
1998
                        dimension.FirstPoint = this._objectReader.Read3BitDouble();
170✔
1999
                        //14 - pt 3BD 14 See DXF documentation.
2000
                        dimension.SecondPoint = this._objectReader.Read3BitDouble();
170✔
2001
                        //10 - pt 3BD 10 See DXF documentation.
2002
                        dimension.DefinitionPoint = this._objectReader.Read3BitDouble();
170✔
2003

2004
                        //Ext ln rot BD 52 Extension line rotation; see DXF documentation.
2005
                        dimension.ExtLineRotation = this._objectReader.ReadBitDouble();
170✔
2006
                }
170✔
2007

2008
                [Obsolete("Can be moved to the common dimension data")]
2009
                private void readCommonDimensionHandles(CadDimensionTemplate template)
2010
                {
672✔
2011
                        //Common Entity Handle Data
2012
                        //H 3 DIMSTYLE(hard pointer)
2013
                        template.StyleHandle = this.handleReference();
672✔
2014
                        //H 2 anonymous BLOCK(hard pointer)
2015
                        template.BlockHandle = this.handleReference();
672✔
2016
                }
672✔
2017

2018
                #endregion
2019

2020
                private CadTemplate readPoint()
2021
                {
2,401✔
2022
                        Point pt = new Point();
2,401✔
2023
                        CadEntityTemplate template = new CadEntityTemplate(pt);
2,401✔
2024

2025
                        this.readCommonEntityData(template);
2,401✔
2026

2027
                        //Point 3BD 10
2028
                        pt.Location = this._objectReader.Read3BitDouble();
2,401✔
2029
                        //Thickness BT 39
2030
                        pt.Thickness = this._objectReader.ReadBitThickness();
2,401✔
2031
                        //Extrusion BE 210
2032
                        pt.Normal = this._objectReader.ReadBitExtrusion();
2,401✔
2033
                        //X - axis ang BD 50 See DXF documentation
2034
                        pt.Rotation = this._objectReader.ReadBitDouble();
2,401✔
2035

2036
                        return template;
2,401✔
2037
                }
2,401✔
2038

2039
                private CadTemplate read3dFace()
2040
                {
77✔
2041
                        Face3D face = new Face3D();
77✔
2042
                        CadEntityTemplate template = new CadEntityTemplate(face);
77✔
2043

2044
                        this.readCommonEntityData(template);
77✔
2045

2046
                        //R13 - R14 Only:
2047
                        if (this.R13_14Only)
77✔
2048
                        {
11✔
2049
                                //1st corner 3BD 10
2050
                                face.FirstCorner = this._objectReader.Read3BitDouble();
11✔
2051
                                //2nd corner 3BD 11
2052
                                face.SecondCorner = this._objectReader.Read3BitDouble();
11✔
2053
                                //3rd corner 3BD 12
2054
                                face.ThirdCorner = this._objectReader.Read3BitDouble();
11✔
2055
                                //4th corner 3BD 13
2056
                                face.FourthCorner = this._objectReader.Read3BitDouble();
11✔
2057
                                //Invis flags BS 70 Invisible edge flags
2058
                                face.Flags = (InvisibleEdgeFlags)this._objectReader.ReadBitShort();
11✔
2059
                        }
11✔
2060

2061
                        //R2000 +:
2062
                        if (this.R2000Plus)
77✔
2063
                        {
66✔
2064
                                //Has no flag ind. B
2065
                                bool noFlags = this._objectReader.ReadBit();
66✔
2066
                                //Z is zero bit B
2067
                                bool zIsZero = this._objectReader.ReadBit();
66✔
2068

2069
                                //1st corner x RD 10
2070
                                double x = this._objectReader.ReadDouble();
66✔
2071
                                //1st corner y RD 20
2072
                                double y = this._objectReader.ReadDouble();
66✔
2073
                                //1st corner z RD 30 Present only if “Z is zero bit” is 0.
2074
                                double z = 0.0;
66✔
2075

2076
                                if (!zIsZero)
66!
2077
                                        z = this._objectReader.ReadDouble();
×
2078

2079
                                face.FirstCorner = new XYZ(x, y, z);
66✔
2080

2081
                                //2nd corner 3DD 11 Use 10 value as default point
2082
                                face.SecondCorner = this._objectReader.Read3BitDoubleWithDefault(face.FirstCorner);
66✔
2083
                                //3rd corner 3DD 12 Use 11 value as default point
2084
                                face.ThirdCorner = this._objectReader.Read3BitDoubleWithDefault(face.SecondCorner);
66✔
2085
                                //4th corner 3DD 13 Use 12 value as default point
2086
                                face.FourthCorner = this._objectReader.Read3BitDoubleWithDefault(face.ThirdCorner);
66✔
2087

2088
                                //Invis flags BS 70 Present it “Has no flag ind.” is 0.
2089
                                if (!noFlags)
66!
2090
                                        face.Flags = (InvisibleEdgeFlags)this._objectReader.ReadBitShort();
×
2091
                        }
66✔
2092

2093
                        return template;
77✔
2094
                }
77✔
2095

2096
                private CadTemplate readPolyfaceMesh()
2097
                {
77✔
2098
                        CadPolyfaceMeshTemplate template = new CadPolyfaceMeshTemplate(new PolyfaceMesh());
77✔
2099

2100
                        //Common Entity Data
2101
                        this.readCommonEntityData(template);
77✔
2102

2103
                        //Numverts BS 71 Number of vertices in the mesh.
2104
                        short nvertices = this._objectReader.ReadBitShort();
77✔
2105
                        //Numfaces BS 72 Number of faces
2106
                        short nfaces = this._objectReader.ReadBitShort();
77✔
2107

2108
                        //R2004 +:
2109
                        if (this.R2004Plus)
77✔
2110
                        {
55✔
2111
                                //Owned Object Count BL Number of objects owned by this object.
2112
                                int ownedVertices = this._objectReader.ReadBitLong();
55✔
2113
                                //H[VERTEX(soft pointer)] Repeats “Owned Object Count” times.
2114
                                for (int i = 0; i < ownedVertices; i++)
880✔
2115
                                {
385✔
2116
                                        template.VerticesHandles.Add(this.handleReference());
385✔
2117
                                }
385✔
2118
                        }
55✔
2119

2120
                        //R13 - R2000:
2121
                        if (this.R13_15Only)
77✔
2122
                        {
22✔
2123
                                //H first VERTEX(soft pointer)
2124
                                template.FirstVerticeHandle = this.handleReference();
22✔
2125
                                //H last VERTEX(soft pointer)
2126
                                template.LastVerticeHandle = this.handleReference();
22✔
2127
                        }
22✔
2128

2129
                        //Common:
2130
                        //H SEQEND(hard owner)
2131
                        template.SeqendHandle = this.handleReference();
77✔
2132

2133
                        return template;
77✔
2134
                }
77✔
2135

2136
                private CadTemplate readPolylineMesh()
2137
                {
×
2138
                        return null;
×
2139
                }
×
2140

2141
                private CadTemplate readSolid()
2142
                {
770✔
2143
                        Solid solid = new Solid();
770✔
2144
                        CadEntityTemplate template = new CadEntityTemplate(solid);
770✔
2145

2146
                        //Common Entity Data
2147
                        this.readCommonEntityData(template);
770✔
2148

2149
                        //Thickness BT 39
2150
                        solid.Thickness = this._objectReader.ReadBitThickness();
770✔
2151

2152
                        //Elevation BD ---Z for 10 - 13.
2153
                        double elevation = this._objectReader.ReadBitDouble();
770✔
2154

2155
                        //1st corner 2RD 10
2156
                        XY firstCorner = this._objectReader.Read2RawDouble();
770✔
2157
                        solid.FirstCorner = new XYZ(firstCorner.X, firstCorner.Y, elevation);
770✔
2158

2159
                        //2nd corner 2RD 11
2160
                        XY point2D2 = this._objectReader.Read2RawDouble();
770✔
2161
                        solid.SecondCorner = new XYZ(point2D2.X, point2D2.Y, elevation);
770✔
2162

2163
                        //3rd corner 2RD 12
2164
                        XY point2D3 = this._objectReader.Read2RawDouble();
770✔
2165
                        solid.ThirdCorner = new XYZ(point2D3.X, point2D3.Y, elevation);
770✔
2166

2167
                        //4th corner 2RD 13
2168
                        XY point2D4 = this._objectReader.Read2RawDouble();
770✔
2169
                        solid.FourthCorner = new XYZ(point2D4.X, point2D4.Y, elevation);
770✔
2170

2171
                        //Extrusion BE 210
2172
                        solid.Normal = this._objectReader.ReadBitExtrusion();
770✔
2173

2174
                        return template;
770✔
2175
                }
770✔
2176

2177
                private CadTemplate readShape()
2178
                {
77✔
2179
                        Shape shape = new Shape();
77✔
2180
                        CadShapeTemplate template = new CadShapeTemplate(shape);
77✔
2181

2182
                        this.readCommonEntityData(template);
77✔
2183

2184
                        //Ins pt 3BD 10
2185
                        shape.InsertionPoint = this._objectReader.Read3BitDouble();
77✔
2186
                        //Scale BD 40 Scale factor, default value 1.
2187
                        shape.Size = this._objectReader.ReadBitDouble();
77✔
2188
                        //Rotation BD 50 Rotation in radians, default value 0.
2189
                        shape.Rotation = this._objectReader.ReadBitDouble();
77✔
2190
                        //Width factor BD 41 Width factor, default value 1.
2191
                        shape.RelativeXScale = this._objectReader.ReadBitDouble();
77✔
2192
                        //Oblique BD 51 Oblique angle in radians, default value 0.
2193
                        shape.ObliqueAngle = this._objectReader.ReadBitDouble();
77✔
2194
                        //Thickness BD 39
2195
                        shape.Thickness = this._objectReader.ReadBitDouble();
77✔
2196

2197
                        //Shapeno BS 2
2198
                        //This is the shape index.
2199
                        //In DXF the shape name is stored.
2200
                        //When reading from DXF, the shape is found by iterating over all the text styles
2201
                        //(SHAPEFILE, see paragraph 20.4.56) and when the text style contains a shape file,
2202
                        //iterating over all the shapes until the one with the matching name is found.
2203
                        shape.ShapeIndex = (ushort)this._objectReader.ReadBitShort();
77✔
2204

2205
                        //Extrusion 3BD 210
2206
                        shape.Normal = this._objectReader.Read3BitDouble();
77✔
2207

2208
                        //H SHAPEFILE (hard pointer)
2209
                        template.ShapeFileHandle = this.handleReference();
77✔
2210

2211
                        return template;
77✔
2212
                }
77✔
2213

2214
                private CadTemplate readViewport()
2215
                {
462✔
2216
                        Viewport viewport = new Viewport();
462✔
2217
                        CadViewportTemplate template = new CadViewportTemplate(viewport);
462✔
2218

2219
                        //Common Entity Data
2220
                        this.readCommonEntityData(template);
462✔
2221

2222
                        //Center 3BD 10
2223
                        viewport.Center = this._objectReader.Read3BitDouble();
462✔
2224
                        //Width BD 40
2225
                        viewport.Width = this._objectReader.ReadBitDouble();
462✔
2226
                        //Height BD 41
2227
                        viewport.Height = this._objectReader.ReadBitDouble();
462✔
2228

2229
                        //R2000 +:
2230
                        if (this.R2000Plus)
462✔
2231
                        {
396✔
2232
                                //View Target 3BD 17
2233
                                viewport.ViewTarget = this._objectReader.Read3BitDouble();
396✔
2234
                                //View Direction 3BD 16
2235
                                viewport.ViewDirection = this._objectReader.Read3BitDouble();
396✔
2236
                                //View Twist Angle BD 51
2237
                                viewport.TwistAngle = this._objectReader.ReadBitDouble();
396✔
2238
                                //View Height BD 45
2239
                                viewport.ViewHeight = this._objectReader.ReadBitDouble();
396✔
2240
                                //Lens Length BD 42
2241
                                viewport.LensLength = this._objectReader.ReadBitDouble();
396✔
2242
                                //Front Clip Z BD 43
2243
                                viewport.FrontClipPlane = this._objectReader.ReadBitDouble();
396✔
2244
                                //Back Clip Z BD 44
2245
                                viewport.BackClipPlane = this._objectReader.ReadBitDouble();
396✔
2246
                                //Snap Angle BD 50
2247
                                viewport.SnapAngle = this._objectReader.ReadBitDouble();
396✔
2248
                                //View Center 2RD 12
2249
                                viewport.ViewCenter = this._objectReader.Read2RawDouble();
396✔
2250
                                //Snap Base 2RD 13
2251
                                viewport.SnapBase = this._objectReader.Read2RawDouble();
396✔
2252
                                //Snap Spacing 2RD 14
2253
                                viewport.SnapSpacing = this._objectReader.Read2RawDouble();
396✔
2254
                                //Grid Spacing 2RD 15
2255
                                viewport.GridSpacing = this._objectReader.Read2RawDouble();
396✔
2256
                                //Circle Zoom BS 72
2257
                                viewport.CircleZoomPercent = this._objectReader.ReadBitShort();
396✔
2258
                        }
396✔
2259

2260
                        //R2007 +:
2261
                        if (this.R2007Plus)
462✔
2262
                                //Grid Major BS 61
2263
                                viewport.MajorGridLineFrequency = this._objectReader.ReadBitShort();
264✔
2264

2265
                        int frozenLayerCount = 0;
462✔
2266
                        //R2000 +:
2267
                        if (this.R2000Plus)
462✔
2268
                        {
396✔
2269
                                //Frozen Layer Count BL
2270
                                frozenLayerCount = this._objectReader.ReadBitLong();
396✔
2271
                                //Status Flags BL 90
2272
                                viewport.Status = (ViewportStatusFlags)this._objectReader.ReadBitLong();
396✔
2273
                                //Style Sheet TV 1
2274
                                viewport.StyleSheetName = this._textReader.ReadVariableText();
396✔
2275
                                //Render Mode RC 281
2276
                                viewport.RenderMode = (RenderMode)this._objectReader.ReadByte();
396✔
2277
                                //UCS at origin B 74
2278
                                viewport.DisplayUcsIcon = this._objectReader.ReadBit();
396✔
2279
                                //UCS per Viewport B 71
2280
                                viewport.UcsPerViewport = this._objectReader.ReadBit();
396✔
2281
                                //UCS Origin 3BD 110
2282
                                viewport.UcsOrigin = this._objectReader.Read3BitDouble();
396✔
2283
                                //UCS X Axis 3BD 111
2284
                                viewport.UcsXAxis = this._objectReader.Read3BitDouble();
396✔
2285
                                //UCS Y Axis 3BD 112
2286
                                viewport.UcsYAxis = this._objectReader.Read3BitDouble();
396✔
2287
                                //UCS Elevation BD 146
2288
                                viewport.Elevation = this._objectReader.ReadBitDouble();
396✔
2289
                                //UCS Ortho View Type BS 79
2290
                                viewport.UcsOrthographicType = (OrthographicType)this._objectReader.ReadBitShort();
396✔
2291
                        }
396✔
2292

2293
                        //R2004 +:
2294
                        if (this.R2004Plus)
462✔
2295
                                //ShadePlot Mode BS 170
2296
                                viewport.ShadePlotMode = (ShadePlotMode)this._objectReader.ReadBitShort();
330✔
2297

2298
                        //R2007 +:
2299
                        if (this.R2007Plus)
462✔
2300
                        {
264✔
2301
                                //Use def. lights B 292
2302
                                viewport.UseDefaultLighting = this._objectReader.ReadBit();
264✔
2303
                                //Def.lighting type RC 282
2304
                                viewport.DefaultLightingType = (LightingType)this._objectReader.ReadByte();
264✔
2305
                                //Brightness BD 141
2306
                                viewport.Brightness = this._objectReader.ReadBitDouble();
264✔
2307
                                //Contrast BD 142
2308
                                viewport.Contrast = this._objectReader.ReadBitDouble();
264✔
2309
                                //Ambient light color CMC 63
2310
                                viewport.AmbientLightColor = this._objectReader.ReadCmColor();
264✔
2311
                        }
264✔
2312

2313
                        //R13 - R14 Only:
2314
                        if (this.R13_14Only)
462✔
2315
                                //H VIEWPORT ENT HEADER(hard pointer)
2316
                                template.ViewportHeaderHandle = this.handleReference();
66✔
2317

2318
                        //R2000 +:
2319
                        if (this.R2000Plus)
462✔
2320
                        {
396✔
2321
                                for (int i = 0; i < frozenLayerCount; ++i)
792!
2322
                                        //H 341 Frozen Layer Handles(use count from above)
2323
                                        //(hard pointer until R2000, soft pointer from R2004 onwards)
2324
                                        template.FrozenLayerHandles.Add(this.handleReference());
×
2325

2326
                                //H 340 Clip boundary handle(soft pointer)
2327
                                template.BoundaryHandle = this.handleReference();
396✔
2328
                        }
396✔
2329

2330
                        //R2000:
2331
                        if (this._version == ACadVersion.AC1015)
462✔
2332
                                //H VIEWPORT ENT HEADER((hard pointer))
2333
                                template.ViewportHeaderHandle = this.handleReference();
66✔
2334

2335
                        //R2000 +:
2336
                        if (this.R2000Plus)
462✔
2337
                        {
396✔
2338
                                //H 345 Named UCS Handle(hard pointer)
2339
                                template.NamedUcsHandle = this.handleReference();
396✔
2340
                                //H 346 Base UCS Handle(hard pointer)
2341
                                template.BaseUcsHandle = this.handleReference();
396✔
2342
                        }
396✔
2343

2344
                        //R2007 +:
2345
                        if (this.R2007Plus)
462✔
2346
                        {
264✔
2347
                                //H 332 Background(soft pointer)
2348
                                long backgroundHandle = (long)this.handleReference();
264✔
2349
                                //H 348 Visual Style(hard pointer)
2350
                                long visualStyleHandle = (long)this.handleReference();
264✔
2351
                                //H 333 Shadeplot ID(soft pointer)
2352
                                long shadePlotIdHandle = (long)this.handleReference();
264✔
2353
                                //H 361 Sun(hard owner)
2354
                                long sunHandle = (long)this.handleReference();
264✔
2355
                        }
264✔
2356

2357
                        return template;
462✔
2358
                }
462✔
2359

2360
                private CadTemplate readEllipse()
2361
                {
85✔
2362
                        Ellipse ellipse = new Ellipse();
85✔
2363
                        CadEntityTemplate template = new CadEntityTemplate(ellipse);
85✔
2364

2365
                        this.readCommonEntityData(template);
85✔
2366

2367
                        //Center 3BD 10 (WCS)
2368
                        ellipse.Center = this._objectReader.Read3BitDouble();
85✔
2369
                        //SM axis vec 3BD 11 Semi-major axis vector (WCS)
2370
                        ellipse.EndPoint = this._objectReader.Read3BitDouble();
85✔
2371
                        //Extrusion 3BD 210
2372
                        ellipse.Normal = this._objectReader.Read3BitDouble();
85✔
2373
                        //Axis ratio BD 40 Minor/major axis ratio
2374
                        ellipse.RadiusRatio = this._objectReader.ReadBitDouble();
85✔
2375
                        //Beg angle BD 41 Starting angle (eccentric anomaly, radians)
2376
                        ellipse.StartParameter = this._objectReader.ReadBitDouble();
85✔
2377
                        //End angle BD 42 Ending angle (eccentric anomaly, radians)
2378
                        ellipse.EndParameter = this._objectReader.ReadBitDouble();
85✔
2379

2380
                        return template;
85✔
2381
                }
85✔
2382

2383
                private CadTemplate readSpline()
2384
                {
154✔
2385
                        Spline spline = new Spline();
154✔
2386
                        CadEntityTemplate template = new CadEntityTemplate(spline);
154✔
2387

2388
                        this.readCommonEntityData(template);
154✔
2389

2390
                        //Scenario BL a flag which is 2 for fitpts only, 1 for ctrlpts/knots.
2391
                        //In 2013 the meaning is somehwat more sophisticated, see knot parameter below.
2392
                        int scenario = this._objectReader.ReadBitLong();
154✔
2393

2394
                        //R2013+:
2395
                        if (this.R2013Plus)
154✔
2396
                        {
44✔
2397
                                //Spline flags 1 BL Spline flags 1:
2398
                                //method fit points = 1,
2399
                                //CV frame show = 2,
2400
                                //Is closed = 4. 
2401
                                //At this point the regular spline flags closed bit is made equal to this bit.
2402
                                //Value is overwritten below in scenario 2 though, 
2403
                                //Use knot parameter = 8
2404
                                spline.Flags1 = (SplineFlags1)this._mergedReaders.ReadBitLong();
44✔
2405

2406
                                //Knot parameter BL Knot parameter:
2407
                                //Chord = 0,
2408
                                //Square root = 1,
2409
                                //Uniform = 2,
2410
                                //Custom = 15
2411
                                //The scenario flag becomes 1 if the knot parameter is Custom or has no fit data, otherwise 2.
2412
                                spline.KnotParameterization = (KnotParameterization)this._mergedReaders.ReadBitLong();
44✔
2413

2414
                                scenario = (spline.KnotParameterization == KnotParameterization.Custom || (spline.Flags1 & SplineFlags1.UseKnotParameter) == 0) ? 1 : 2;
44✔
2415
                        }
44✔
2416
                        else if (scenario == 2)
110!
2417
                        {
×
2418
                                spline.Flags1 |= SplineFlags1.MethodFitPoints;
×
2419
                        }
×
2420
                        else
2421
                        {
110✔
2422
                                //If the spline does not have fit data, then the knot parameter should become Custom.
2423
                                spline.KnotParameterization = KnotParameterization.Custom;
110✔
2424
                        }
110✔
2425

2426
                        //Common:
2427
                        //Degree BL degree of this spline
2428
                        spline.Degree = this._objectReader.ReadBitLong();
154✔
2429

2430
                        int numfitpts = 0;
154✔
2431
                        int numknots = 0;
154✔
2432
                        int numctrlpts = 0;
154✔
2433
                        bool flag = false;
154✔
2434
                        switch (scenario)
154✔
2435
                        {
2436
                                case 1:
2437
                                        //Rational B flag bit 2
2438
                                        if (this._objectReader.ReadBit())
132!
2439
                                                spline.Flags |= SplineFlags.Rational;
×
2440
                                        //Closed B flag bit 0
2441
                                        if (this._objectReader.ReadBit())
132!
2442
                                                spline.Flags |= SplineFlags.Closed;
×
2443
                                        //Periodic B flag bit 1
2444
                                        if (this._objectReader.ReadBit())
132!
2445
                                                spline.Flags |= SplineFlags.Periodic;
×
2446
                                        //Knot tol BD 42
2447
                                        spline.KnotTolerance = this._objectReader.ReadBitDouble();
132✔
2448
                                        //Ctrl tol BD 43
2449
                                        spline.ControlPointTolerance = this._objectReader.ReadBitDouble();
132✔
2450

2451
                                        //Numknots BL 72 This is stored as a LONG
2452
                                        //although it is defined in DXF as a short.
2453
                                        //You can see this if you create a spline with >=256 knots.
2454
                                        numknots = this._objectReader.ReadBitLong();
132✔
2455
                                        //Numctrlpts BL 73 Number of 10's (and 41's, if weighted) that follow.
2456
                                        //Same, stored as LONG, defined in DXF as a short.
2457
                                        numctrlpts = this._objectReader.ReadBitLong();
132✔
2458
                                        //Weight B Seems to be an echo of the 4 bit on the flag for "weights present".
2459
                                        flag = this._objectReader.ReadBit();
132✔
2460
                                        break;
132✔
2461
                                case 2:
2462
                                        //Fit Tol BD 44
2463
                                        spline.FitTolerance = this._objectReader.ReadBitDouble();
22✔
2464
                                        //Beg tan vec 3BD 12 Beginning tangent direction vector (normalized).
2465
                                        spline.StartTangent = this._objectReader.Read3BitDouble();
22✔
2466
                                        //End tan vec 3BD 13 Ending tangent direction vector (normalized).
2467
                                        spline.EndTangent = this._objectReader.Read3BitDouble();
22✔
2468
                                        //num fit pts BL 74 Number of fit points.
2469
                                        //Stored as a LONG, although it is defined in DXF as a short.
2470
                                        //You can see this if you create a spline with >=256 fit points
2471
                                        numfitpts = this._objectReader.ReadBitLong();
22✔
2472
                                        break;
22✔
2473
                        }
2474

2475
                        for (int i = 0; i < numknots; i++)
2,420✔
2476
                        {
1,056✔
2477
                                //Knot BD knot value
2478
                                spline.Knots.Add(this._objectReader.ReadBitDouble());
1,056✔
2479
                        }
1,056✔
2480
                        for (int j = 0; j < numctrlpts; j++)
1,364✔
2481
                        {
528✔
2482
                                //Control pt 3BD 10
2483
                                spline.ControlPoints.Add(this._objectReader.Read3BitDouble());
528✔
2484
                                if (flag)
528!
2485
                                {
×
2486
                                        //Weight D 41 if present as indicated by 4 bit on flag
2487
                                        spline.Weights.Add(this._objectReader.ReadBitDouble());
×
2488
                                }
×
2489
                        }
528✔
2490
                        for (int k = 0; k < numfitpts; k++)
396✔
2491
                        {
44✔
2492
                                //Fit pt 3BD
2493
                                spline.FitPoints.Add(this._objectReader.Read3BitDouble());
44✔
2494
                        }
44✔
2495

2496
                        return template;
154✔
2497
                }
154✔
2498

2499
                private CadTemplate readRay()
2500
                {
77✔
2501
                        Ray ray = new Ray();
77✔
2502
                        CadEntityTemplate template = new CadEntityTemplate(ray);
77✔
2503

2504
                        this.readCommonEntityData(template);
77✔
2505

2506
                        //Point 3BD 10
2507
                        ray.StartPoint = this._objectReader.Read3BitDouble();
77✔
2508
                        //Vector 3BD 11
2509
                        ray.Direction = this._objectReader.Read3BitDouble();
77✔
2510

2511
                        return template;
77✔
2512
                }
77✔
2513

2514
                private CadTemplate readXLine()
2515
                {
77✔
2516
                        XLine xline = new XLine();
77✔
2517
                        CadEntityTemplate template = new CadEntityTemplate(xline);
77✔
2518

2519
                        this.readCommonEntityData(template);
77✔
2520

2521
                        //3 RD: a point on the construction line
2522
                        xline.FirstPoint = this._objectReader.Read3BitDouble();
77✔
2523
                        //3 RD : another point
2524
                        xline.Direction = this._objectReader.Read3BitDouble();
77✔
2525

2526
                        return template;
77✔
2527
                }
77✔
2528

2529
                private CadTemplate readDictionaryWithDefault()
2530
                {
86✔
2531
                        CadDictionaryWithDefault dictionary = new CadDictionaryWithDefault();
86✔
2532
                        CadDictionaryWithDefaultTemplate template = new CadDictionaryWithDefaultTemplate(dictionary);
86✔
2533

2534
                        this.readCommonDictionary(template);
86✔
2535

2536
                        //H 7 Default entry (hard pointer)
2537
                        template.DefaultEntryHandle = this.handleReference();
86✔
2538

2539
                        return template;
86✔
2540
                }
86✔
2541

2542
                private CadTemplate readDictionary()
2543
                {
7,666✔
2544
                        CadDictionary cadDictionary = new CadDictionary();
7,666✔
2545
                        CadDictionaryTemplate template = new CadDictionaryTemplate(cadDictionary);
7,666✔
2546

2547
                        this.readCommonDictionary(template);
7,666✔
2548

2549
                        if (cadDictionary.Handle == this._builder.HeaderHandles.DICTIONARY_NAMED_OBJECTS)
7,666✔
2550
                        {
98✔
2551

2552
                        }
98✔
2553

2554
                        return template;
7,666✔
2555
                }
7,666✔
2556

2557
                private void readCommonDictionary(CadDictionaryTemplate template)
2558
                {
7,752✔
2559
                        this.readCommonNonEntityData(template);
7,752✔
2560

2561
                        //Common:
2562
                        //Numitems L number of dictonary items
2563
                        int nentries = this._objectReader.ReadBitLong();
7,752✔
2564

2565
                        //R14 Only:
2566
                        if (this._version == ACadVersion.AC1014)
7,752✔
2567
                        {
1,847✔
2568
                                //Unknown R14 RC Unknown R14 byte, has always been 0
2569
                                byte zero = this._objectReader.ReadByte();
1,847✔
2570
                        }
1,847✔
2571
                        //R2000 +:
2572
                        if (this.R2000Plus)
7,752✔
2573
                        {
5,875✔
2574
                                //Cloning flag BS 281
2575
                                template.CadObject.ClonningFlags = (DictionaryCloningFlags)this._objectReader.ReadBitShort();
5,875✔
2576
                                //Hard Owner flag RC 280
2577
                                template.CadObject.HardOwnerFlag = this._objectReader.ReadByte() > 0;
5,875✔
2578
                        }
5,875✔
2579

2580
                        //Common:
2581
                        for (int i = 0; i < nentries; ++i)
50,242✔
2582
                        {
17,369✔
2583
                                //Text TV string name of dictionary entry, numitems entries
2584
                                string name = this._textReader.ReadVariableText();
17,369✔
2585
                                //Handle refs H parenthandle (soft relative pointer)
2586
                                //[Reactors(soft pointer)]
2587
                                //xdicobjhandle(hard owner)
2588
                                //itemhandles (soft owner)
2589
                                ulong handle = this.handleReference();
17,369✔
2590

2591
                                if (handle == 0 || string.IsNullOrEmpty(name))
17,369!
2592
                                        continue;
12✔
2593

2594
                                template.Entries.Add(name, handle);
17,357✔
2595
                        }
17,357✔
2596
                }
7,752✔
2597

2598
                private CadTemplate readDictionaryVar()
2599
                {
1,105✔
2600
                        DictionaryVariable dictvar = new DictionaryVariable();
1,105✔
2601
                        CadTemplate<DictionaryVariable> template = new CadTemplate<DictionaryVariable>(dictvar);
1,105✔
2602

2603
                        this.readCommonNonEntityData(template);
1,105✔
2604

2605
                        //Intval RC an integer value
2606
                        this._objectReader.ReadByte();
1,105✔
2607

2608
                        //BS a string
2609
                        dictvar.Value = this._textReader.ReadVariableText();
1,105✔
2610

2611
                        return template;
1,105✔
2612
                }
1,105✔
2613

2614
                private CadTemplate readMText()
2615
                {
1,617✔
2616
                        MText mtext = new MText();
1,617✔
2617
                        CadTextEntityTemplate template = new CadTextEntityTemplate(mtext);
1,617✔
2618

2619
                        return this.readMText(template, true);
1,617✔
2620
                }
1,617✔
2621

2622
                private CadTemplate readMText(CadTextEntityTemplate template, bool readCommonData)
2623
                {
1,639✔
2624
                        MText mtext = template.CadObject as MText;
1,639✔
2625

2626
                        if (readCommonData)
1,639✔
2627
                        {
1,617✔
2628
                                this.readCommonEntityData(template);
1,617✔
2629
                        }
1,617✔
2630

2631
                        //Insertion pt3 BD 10 First picked point. (Location relative to text depends on attachment point (71).)
2632
                        mtext.InsertPoint = this._objectReader.Read3BitDouble();
1,639✔
2633
                        //Extrusion 3BD 210 Undocumented; appears in DXF and entget, but ACAD doesn't even bother to adjust it to unit length.
2634
                        mtext.Normal = this._objectReader.Read3BitDouble();
1,639✔
2635
                        //X-axis dir 3BD 11 Apparently the text x-axis vector. (Why not just a rotation?) ACAD maintains it as a unit vector.
2636
                        mtext.AlignmentPoint = this._objectReader.Read3BitDouble();
1,639✔
2637
                        //Rect width BD 41 Reference rectangle width (width picked by the user).
2638
                        mtext.RectangleWidth = this._objectReader.ReadBitDouble();
1,639✔
2639

2640
                        //R2007+:
2641
                        if (this.R2007Plus)
1,639✔
2642
                        {
946✔
2643
                                //Rect height BD 46 Reference rectangle height.
2644
                                mtext.RectangleHeight = this._objectReader.ReadBitDouble();
946✔
2645
                        }
946✔
2646

2647
                        //Common:
2648
                        //Text height BD 40 Undocumented
2649
                        mtext.Height = this._objectReader.ReadBitDouble();
1,639✔
2650
                        //Attachment BS 71 Similar to justification; see DXF doc
2651
                        mtext.AttachmentPoint = (AttachmentPointType)this._objectReader.ReadBitShort();
1,639✔
2652
                        //Drawing dir BS 72 Left to right, etc.; see DXF doc
2653
                        mtext.DrawingDirection = (DrawingDirectionType)this._objectReader.ReadBitShort();
1,639✔
2654
                        //Extents ht BD ---Undocumented and not present in DXF or entget
2655
                        this._objectReader.ReadBitDouble();
1,639✔
2656
                        //Extents wid BD ---Undocumented and not present in DXF or entget
2657
                        this._objectReader.ReadBitDouble();
1,639✔
2658
                        //Text TV 1 All text in one long string
2659
                        mtext.Value = this._textReader.ReadVariableText();
1,639✔
2660

2661
                        //H 7 STYLE (hard pointer)
2662
                        template.StyleHandle = this.handleReference();
1,639✔
2663

2664
                        //R2000+:
2665
                        if (this.R2000Plus)
1,639✔
2666
                        {
1,408✔
2667
                                //Linespacing Style BS 73
2668
                                mtext.LineSpacingStyle = (LineSpacingStyleType)this._objectReader.ReadBitShort();
1,408✔
2669
                                //Linespacing Factor BD 44
2670
                                mtext.LineSpacing = this._objectReader.ReadBitDouble();
1,408✔
2671
                                //Unknown bit B
2672
                                this._objectReader.ReadBit();
1,408✔
2673
                        }
1,408✔
2674

2675
                        //R2004+:
2676
                        if (this.R2004Plus)
1,639✔
2677
                        {
1,177✔
2678
                                //Background flags BL 90 0 = no background, 1 = background fill, 2 = background fill with drawing fill color, 0x10 = text frame (R2018+)
2679
                                mtext.BackgroundFillFlags = (BackgroundFillFlags)this._objectReader.ReadBitLong();
1,177✔
2680

2681
                                //background flags has bit 0x01 set, or in case of R2018 bit 0x10:
2682
                                if ((mtext.BackgroundFillFlags & BackgroundFillFlags.UseBackgroundFillColor) != BackgroundFillFlags.None
1,177!
2683
                                        || this._version > ACadVersion.AC1027
1,177✔
2684
                                        && (mtext.BackgroundFillFlags & BackgroundFillFlags.TextFrame) > 0)
1,177✔
2685
                                {
×
2686
                                        //Background scale factor        BL 45 default = 1.5
2687
                                        mtext.BackgroundScale = this._objectReader.ReadBitDouble();
×
2688
                                        //Background color CMC 63
2689
                                        mtext.BackgroundColor = this._mergedReaders.ReadCmColor();
×
2690
                                        //Background transparency BL 441
2691
                                        mtext.BackgroundTransparency = new Transparency((short)this._objectReader.ReadBitLong());
×
2692
                                }
×
2693
                        }
1,177✔
2694

2695
                        //R2018+
2696
                        if (!this.R2018Plus)
1,639✔
2697
                                return template;
1,386✔
2698

2699
                        //Is NOT annotative B
2700
                        mtext.IsAnnotative = !this._objectReader.ReadBit();
253✔
2701

2702
                        //IF MTEXT is not annotative
2703
                        if (!mtext.IsAnnotative)
253✔
2704
                        {
253✔
2705
                                //Version BS Default 0
2706
                                var version = this._objectReader.ReadBitShort();
253✔
2707
                                //Default flag B Default true
2708
                                var defaultFlag = this._objectReader.ReadBit();
253✔
2709

2710
                                //BEGIN REDUNDANT FIELDS(see above for descriptions)
2711
                                //Registered application H Hard pointer
2712
                                ulong appHandle = this.handleReference();
253✔
2713

2714
                                //TODO: finish Mtext reader, save redundant fields??
2715

2716
                                //Attachment point BL
2717
                                AttachmentPointType attachmentPoint = (AttachmentPointType)this._objectReader.ReadBitLong();
253✔
2718
                                //X - axis dir 3BD 10
2719
                                this._objectReader.Read3BitDouble();
253✔
2720
                                //Insertion point 3BD 11
2721
                                this._objectReader.Read3BitDouble();
253✔
2722
                                //Rect width BD 40
2723
                                this._objectReader.ReadBitDouble();
253✔
2724
                                //Rect height BD 41
2725
                                this._objectReader.ReadBitDouble();
253✔
2726
                                //Extents width BD 42
2727
                                this._objectReader.ReadBitDouble();
253✔
2728
                                //Extents height BD 43
2729
                                this._objectReader.ReadBitDouble();
253✔
2730
                                //END REDUNDANT FIELDS
2731

2732
                                //Column type BS 71 0 = No columns, 1 = static columns, 2 = dynamic columns
2733
                                mtext.Column.ColumnType = (ColumnType)this._objectReader.ReadBitShort();
253✔
2734
                                //IF Has Columns data(column type is not 0)
2735
                                if (mtext.Column.ColumnType != ColumnType.NoColumns)
253✔
2736
                                {
44✔
2737
                                        //Column height count BL 72
2738
                                        int count = this._objectReader.ReadBitLong();
44✔
2739
                                        //Columnn width BD 44
2740
                                        mtext.Column.ColumnWidth = this._objectReader.ReadBitDouble();
44✔
2741
                                        //Gutter BD 45
2742
                                        mtext.Column.ColumnGutter = this._objectReader.ReadBitDouble();
44✔
2743
                                        //Auto height? B 73
2744
                                        mtext.Column.ColumnAutoHeight = this._objectReader.ReadBit();
44✔
2745
                                        //Flow reversed? B 74
2746
                                        mtext.Column.ColumnFlowReversed = this._objectReader.ReadBit();
44✔
2747

2748
                                        //IF not auto height and column type is dynamic columns
2749
                                        if (!mtext.Column.ColumnAutoHeight && mtext.Column.ColumnType == ColumnType.DynamicColumns && count > 0)
44!
2750
                                        {
44✔
2751
                                                for (int i = 0; i < count; ++i)
176✔
2752
                                                {
44✔
2753
                                                        //Column height BD 46
2754
                                                        mtext.Column.ColumnHeights.Add(this._objectReader.ReadBitDouble());
44✔
2755
                                                }
44✔
2756
                                        }
44✔
2757
                                }
44✔
2758
                        }
253✔
2759

2760
                        return template;
253✔
2761
                }
1,639✔
2762

2763
                private CadTemplate readLeader()
2764
                {
77✔
2765
                        Leader leader = new Leader();
77✔
2766
                        CadLeaderTemplate template = new CadLeaderTemplate(leader);
77✔
2767

2768
                        this.readCommonEntityData(template);
77✔
2769

2770
                        //Unknown bit B --- Always seems to be 0.
2771
                        this._objectReader.ReadBit();
77✔
2772

2773
                        //Annot type BS --- Annotation type (NOT bit-coded):
2774
                        //Value 0 : MTEXT
2775
                        //Value 1 : TOLERANCE
2776
                        //Value 2 : INSERT
2777
                        //Value 3 : None
2778
                        leader.CreationType = (LeaderCreationType)this._objectReader.ReadBitShort();
77✔
2779
                        //path type BS ---
2780
                        leader.PathType = (LeaderPathType)this._objectReader.ReadBitShort();
77✔
2781

2782
                        //numpts BL --- number of points
2783
                        int npts = this._objectReader.ReadBitLong();
77✔
2784
                        for (int i = 0; i < npts; i++)
616✔
2785
                        {
231✔
2786
                                //point 3BD 10 As many as counter above specifies.
2787
                                leader.Vertices.Add(this._objectReader.Read3BitDouble());
231✔
2788
                        }
231✔
2789

2790
                        //Origin 3BD --- The leader plane origin (by default it’s the first point)
2791
                        //Is necessary to store this value?
2792
                        this._objectReader.Read3BitDouble();
77✔
2793
                        //Extrusion 3BD 210
2794
                        leader.Normal = this._objectReader.Read3BitDouble();
77✔
2795
                        //x direction 3BD 211
2796
                        leader.HorizontalDirection = this._objectReader.Read3BitDouble();
77✔
2797
                        //offsettoblockinspt 3BD 212 Used when the BLOCK option is used. Seems to be an unused feature.
2798
                        leader.BlockOffset = this._objectReader.Read3BitDouble();
77✔
2799

2800
                        //R14+:
2801
                        if (this._version >= ACadVersion.AC1014)
77✔
2802
                        {
77✔
2803
                                //Endptproj 3BD --- A non-planar leader gives a point that projects the endpoint back to the annotation.
2804
                                //It's the offset from the endpoint of the leader to the annotation, taking into account the extrusion direction.
2805
                                leader.AnnotationOffset = this._objectReader.Read3BitDouble();
77✔
2806
                        }
77✔
2807

2808
                        //R13-R14 Only:
2809
                        if (this.R13_14Only)
77✔
2810
                        {
11✔
2811
                                //DIMGAP BD --- The value of DIMGAP in the associated DIMSTYLE at the time of creation, multiplied by the dimscale in that dimstyle.
2812
                                leader.Style.DimensionLineGap = this._objectReader.ReadBitDouble();
11✔
2813
                        }
11✔
2814

2815
                        //Common:
2816
                        if (this._version <= ACadVersion.AC1021)
77✔
2817
                        {
44✔
2818
                                //For higher versions this values are wrong and it works best if they are not read
2819
                                //Box height BD 40 MTEXT extents height. (A text box is slightly taller, probably by some DIMvar amount.)
2820
                                leader.TextHeight = this._objectReader.ReadBitDouble();
44✔
2821
                                //Box width BD 41 MTEXT extents width. (A text box is slightly wider, probably by some DIMvar amount.)
2822
                                leader.TextWidth = this._objectReader.ReadBitDouble();
44✔
2823
                        }
44✔
2824

2825
                        //Hooklineonxdir B hook line is on x direction if 1
2826
                        leader.HookLineDirection = this._objectReader.ReadBit();
77✔
2827
                        //Arrowheadon B arrowhead on indicator
2828
                        leader.ArrowHeadEnabled = this._objectReader.ReadBit();
77✔
2829

2830
                        //R13-R14 Only:
2831
                        if (this.R13_14Only)
77✔
2832
                        {
11✔
2833
                                //Arrowheadtype BS arrowhead type
2834
                                this._objectReader.ReadBitShort();
11✔
2835
                                //Dimasz BD DIMASZ at the time of creation, multiplied by DIMSCALE
2836
                                template.Dimasz = this._objectReader.ReadBitDouble();
11✔
2837
                                //Unknown B
2838
                                this._objectReader.ReadBit();
11✔
2839
                                //Unknown B
2840
                                this._objectReader.ReadBit();
11✔
2841
                                //Unknown BS
2842
                                this._objectReader.ReadBitShort();
11✔
2843
                                //Byblockcolor BS
2844
                                this._objectReader.ReadBitShort();
11✔
2845
                                //Unknown B
2846
                                this._objectReader.ReadBit();
11✔
2847
                                //Unknown B
2848
                                this._objectReader.ReadBit();
11✔
2849
                        }
11✔
2850

2851
                        //R2000+:
2852
                        if (this.R2000Plus)
77✔
2853
                        {
66✔
2854
                                //Unknown BS
2855
                                this._objectReader.ReadBitShort();
66✔
2856
                                //Unknown B
2857
                                this._objectReader.ReadBit();
66✔
2858
                                //Unknown B
2859
                                this._objectReader.ReadBit();
66✔
2860
                        }
66✔
2861

2862
                        //H 340 Associated annotation
2863
                        template.AnnotationHandle = this.handleReference();
77✔
2864
                        //H 2 DIMSTYLE (hard pointer)
2865
                        template.DIMSTYLEHandle = this.handleReference();
77✔
2866

2867
                        return template;
77✔
2868
                }
77✔
2869

2870
                private CadTemplate readMultiLeader()
2871
                {
161✔
2872
                        MultiLeader mLeader = new MultiLeader();
161✔
2873
                        CadMLeaderTemplate template = new CadMLeaderTemplate(mLeader);
161✔
2874

2875
                        this.readCommonEntityData(template);
161✔
2876

2877
                        if (this.R2010Plus)
161✔
2878
                        {
89✔
2879
                                //        270 Version, expected to be 2
2880
                                var f270 = this._objectReader.ReadBitShort();
89✔
2881
                        }
89✔
2882

2883
                        mLeader.ContextData = this.readMultiLeaderAnnotContext(template);
161✔
2884

2885
                        //        Multileader Common data
2886
                        //        340 Leader StyleId (handle)
2887
                        template.LeaderStyleHandle = this.handleReference();
161✔
2888
                        //BL        90  Property Override Flags (int32)
2889
                        mLeader.PropertyOverrideFlags = (MultiLeaderPropertyOverrideFlags)this._objectReader.ReadBitLong();
161✔
2890
                        //BS        170 LeaderLineType (short)
2891
                        mLeader.PathType = (MultiLeaderPathType)this._objectReader.ReadBitShort();
161✔
2892
                        //CMC        91  Leade LineColor (Color)
2893
                        mLeader.LineColor = _mergedReaders.ReadCmColor();
161✔
2894
                        //H         341 LeaderLineTypeID (handle/LineType)
2895
                        template.LeaderLineTypeHandle = this.handleReference();
161✔
2896

2897
                        //BL        171 LeaderLine Weight
2898
                        mLeader.LeaderLineWeight = (LineweightType)this._objectReader.ReadBitLong();
161✔
2899
                        //B  290 Enable Landing
2900
                        mLeader.EnableLanding = this._objectReader.ReadBit();
161✔
2901
                        //B  291 Enable Dogleg
2902
                        mLeader.EnableDogleg = this._objectReader.ReadBit();
161✔
2903

2904
                        //  41  Dogleg Length / Landing distance
2905
                        mLeader.LandingDistance = this._objectReader.ReadBitDouble();
161✔
2906
                        //  342 Arrowhead ID
2907
                        template.ArrowheadHandle = this.handleReference();
161✔
2908

2909
                        //  42  Arrowhead Size
2910
                        mLeader.ArrowheadSize = this._objectReader.ReadBitDouble();
161✔
2911
                        //BS        172 Content Type
2912
                        mLeader.ContentType = (LeaderContentType)this._objectReader.ReadBitShort();
161✔
2913
                        //H                343 Text Style ID (handle/TextStyle)
2914
                        template.MTextStyleHandle = this.handleReference();
161✔
2915

2916
                        //  173 Text Left Attachment Type
2917
                        mLeader.TextLeftAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
161✔
2918
                        //  95  Text Right Attachement Type
2919
                        mLeader.TextRightAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
161✔
2920
                        //  174 Text Angle Type
2921
                        mLeader.TextAngle = (TextAngleType)this._objectReader.ReadBitShort();
161✔
2922
                        //  175 Text Alignment Type
2923
                        mLeader.TextAlignment = (TextAlignmentType)this._objectReader.ReadBitShort();
161✔
2924
                        //  92  Text Color
2925
                        mLeader.TextColor = this._mergedReaders.ReadCmColor();
161✔
2926
                        //  292 Enable Frame Text
2927
                        mLeader.TextFrame = this._objectReader.ReadBit();
161✔
2928
                        //  344 Block Content ID
2929
                        template.BlockContentHandle = this.handleReference();
161✔
2930
                        //  93  Block Content Color
2931
                        mLeader.BlockContentColor = this._mergedReaders.ReadCmColor();
161✔
2932
                        //  10  Block Content Scale
2933
                        mLeader.BlockContentScale = this._objectReader.Read3BitDouble();
161✔
2934
                        //  43  Block Content Rotation
2935
                        mLeader.BlockContentRotation = this._objectReader.ReadBitDouble();
161✔
2936
                        //  176 Block Content Connection Type
2937
                        mLeader.BlockContentConnection = (BlockContentConnectionType)this._objectReader.ReadBitShort();
161✔
2938
                        //  293 Enable Annotation Scale/Is annotative
2939
                        mLeader.EnableAnnotationScale = this._objectReader.ReadBit();
161✔
2940

2941
                        //-R2007
2942
                        if (this.R2007Pre)
161✔
2943
                        {
72✔
2944
                                //        BL number of arrow  heads
2945
                                int arrowHeadCount = this._objectReader.ReadBitLong();
72✔
2946
                                for (int ah = 0; ah < arrowHeadCount; ah++)
144!
2947
                                {
×
2948
                                        //        //  DXF:        94  BL Arrowhead Index (DXF)
2949
                                        //        //        ODA:        94 B Is Default
2950
                                        //        int arrowheadIndex = _objectReader.ReadBitLong();
2951
                                        bool isDefault = _objectReader.ReadBit();
×
2952

2953
                                        //  345 Arrowhead ID
2954
                                        template.ArrowheadHandles.Add(this.handleReference(), isDefault);
×
2955
                                }
×
2956
                        }
72✔
2957

2958
                        //        BL Number of Block Labels 
2959
                        int blockLabelCount = this._objectReader.ReadBitLong();
161✔
2960
                        for (int bl = 0; bl < blockLabelCount; bl++)
322!
2961
                        {
×
2962
                                //  330 Block Attribute definition handle (hard pointer)
2963
                                var attributeHandle = this.handleReference();
×
2964
                                var blockAttribute = new MultiLeader.BlockAttribute()
×
2965
                                {
×
2966
                                        //  302 Block Attribute Text String
×
2967
                                        Text = this._textReader.ReadVariableText(),
×
2968
                                        //  177 Block Attribute Index
×
2969
                                        Index = this._objectReader.ReadBitShort(),
×
2970
                                        //  44  Block Attribute Width
×
2971
                                        Width = this._objectReader.ReadBitDouble()
×
2972
                                };
×
2973
                                mLeader.BlockAttributes.Add(blockAttribute);
×
2974
                                template.BlockAttributeHandles.Add(blockAttribute, attributeHandle);
×
2975
                        }
×
2976

2977
                        //  294 Text Direction Negative
2978
                        mLeader.TextDirectionNegative = this._objectReader.ReadBit();
161✔
2979
                        //  178 Text Align in IPE
2980
                        mLeader.TextAligninIPE = this._objectReader.ReadBitShort();
161✔
2981
                        //  179 Text Attachment Point
2982
                        mLeader.TextAttachmentPoint = (TextAttachmentPointType)this._objectReader.ReadBitShort();
161✔
2983
                        //        45        BD        ScaleFactor
2984
                        mLeader.ScaleFactor = this._objectReader.ReadBitDouble();
161✔
2985

2986
                        if (this.R2010Plus)
161✔
2987
                        {
89✔
2988
                                //  271 Text attachment direction for MText contents
2989
                                mLeader.TextAttachmentDirection = (TextAttachmentDirectionType)this._objectReader.ReadBitShort();
89✔
2990
                                //  272 Bottom text attachment direction (sequence my be interchanged)
2991
                                mLeader.TextBottomAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
89✔
2992
                                //  273 Top text attachment direction
2993
                                mLeader.TextTopAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
89✔
2994
                        }
89✔
2995

2996
                        if (this.R2013Plus)
161✔
2997
                        {
64✔
2998
                                //        295 Leader extended to text
2999
                                mLeader.ExtendedToText = this._objectReader.ReadBit();
64✔
3000
                        }
64✔
3001

3002
                        return template;
161✔
3003
                }
161✔
3004

3005
                private MultiLeaderAnnotContext readMultiLeaderAnnotContext(CadMLeaderTemplate template)
3006
                {
161✔
3007
                        MultiLeaderAnnotContext annotContext = new MultiLeaderAnnotContext();
161✔
3008

3009
                        //        BL        -        Number of leader roots
3010
                        int leaderRootCount = this._objectReader.ReadBitLong();
161✔
3011
                        for (int i = 0; i < leaderRootCount; i++)
644✔
3012
                        {
161✔
3013
                                annotContext.LeaderRoots.Add(this.readLeaderRoot(template));
161✔
3014
                        }
161✔
3015

3016
                        //        Common
3017
                        //        BD        40        Overall scale
3018
                        annotContext.ScaleFactor = this._objectReader.ReadBitDouble();
161✔
3019
                        //        3BD        10        Content base point
3020
                        annotContext.ContentBasePoint = this._objectReader.Read3BitDouble();
161✔
3021
                        //        BD        41        Text height
3022
                        annotContext.TextHeight = this._objectReader.ReadBitDouble();
161✔
3023
                        //        BD        140        Arrow head size
3024
                        annotContext.ArrowheadSize = this._objectReader.ReadBitDouble();
161✔
3025
                        //  BD        145        Landing gap
3026
                        annotContext.LandingGap = this._objectReader.ReadBitDouble();
161✔
3027
                        //        BS        174        Style left text attachment type. See also MLEADER style left text attachment type for values. Relevant if mleader attachment direction is horizontal.
3028
                        annotContext.TextLeftAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
161✔
3029
                        //        BS        175        Style right text attachment type. See also MLEADER style left text attachment type for values. Relevant if mleader attachment direction is horizontal.
3030
                        annotContext.TextRightAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
161✔
3031
                        //        BS        176        Text align type (0 = left, 1 = center, 2 = right)
3032
                        annotContext.TextAlignment = (TextAlignmentType)this._objectReader.ReadBitShort();
161✔
3033
                        //        BS        177        Attachment type (0 = content extents, 1 = insertion point).
3034
                        annotContext.BlockContentConnection = (BlockContentConnectionType)this._objectReader.ReadBitShort();
161✔
3035
                        //        B        290        Has text contents
3036
                        annotContext.HasTextContents = this._objectReader.ReadBit();
161✔
3037
                        if (annotContext.HasTextContents)
161!
3038
                        {
161✔
3039
                                //        TV        304        Text label
3040
                                annotContext.TextLabel = this._textReader.ReadVariableText();
161✔
3041
                                //        3BD        11        Normal vector
3042
                                annotContext.TextNormal = this._objectReader.Read3BitDouble();
161✔
3043
                                //        H        340        Text style handle (hard pointer)
3044
                                template.AnnotContextTextStyleHandle = this.handleReference();
161✔
3045
                                //        3BD        12        Location
3046
                                annotContext.TextLocation = this._objectReader.Read3BitDouble();
161✔
3047
                                //        3BD        13        Direction
3048
                                annotContext.Direction = this._objectReader.Read3BitDouble();
161✔
3049
                                //        BD        42        Rotation (radians)
3050
                                annotContext.TextRotation = this._objectReader.ReadBitDouble();
161✔
3051
                                //        BD        43        Boundary width
3052
                                annotContext.BoundaryWidth = this._objectReader.ReadBitDouble();
161✔
3053
                                //        BD        44        Boundary height
3054
                                annotContext.BoundaryHeight = this._objectReader.ReadBitDouble();
161✔
3055
                                //        BD        45        Line spacing factor
3056
                                annotContext.LineSpacingFactor = this._objectReader.ReadBitDouble();
161✔
3057
                                //        BS        170        Line spacing style (1 = at least, 2 = exactly)
3058
                                annotContext.LineSpacing = (LineSpacingStyle)this._objectReader.ReadBitShort();
161✔
3059
                                //        CMC        90        Text color
3060
                                annotContext.TextColor = this._objectReader.ReadCmColor();
161✔
3061
                                //        BS        171        Alignment (1 = left, 2 = center, 3 = right)
3062
                                annotContext.TextAttachmentPoint = (TextAttachmentPointType)this._objectReader.ReadBitShort();
161✔
3063
                                //        BS        172        Flow direction (1 = horizontal, 3 = vertical, 6 = by style)
3064
                                annotContext.FlowDirection = (FlowDirectionType)this._objectReader.ReadBitShort();
161✔
3065
                                //        CMC        91        Background fill color
3066
                                annotContext.BackgroundFillColor = this._objectReader.ReadCmColor();
161✔
3067
                                //        BD        141        Background scale factor
3068
                                annotContext.BackgroundScaleFactor = this._objectReader.ReadBitDouble();
161✔
3069
                                //        BL        92        Background transparency
3070
                                annotContext.BackgroundTransparency = this._objectReader.ReadBitLong();
161✔
3071
                                //        B        291        Is background fill enabled
3072
                                annotContext.BackgroundFillEnabled = this._objectReader.ReadBit();
161✔
3073
                                //        B        292        Is background mask fill on
3074
                                annotContext.BackgroundMaskFillOn = this._objectReader.ReadBit();
161✔
3075
                                //        BS        173        Column type (ODA writes 0), *TODO: what meaning for values?
3076
                                annotContext.ColumnType = this._objectReader.ReadBitShort();
161✔
3077
                                //        B        293        Is text height automatic?
3078
                                annotContext.TextHeightAutomatic = this._objectReader.ReadBit();
161✔
3079
                                //        BD        142        Column width
3080
                                annotContext.ColumnWidth = this._objectReader.ReadBitDouble();
161✔
3081
                                //        BD        143        Column gutter
3082
                                annotContext.ColumnGutter = this._objectReader.ReadBitDouble();
161✔
3083
                                //        B        294        Column flow reversed
3084
                                annotContext.ColumnFlowReversed = this._objectReader.ReadBit();
161✔
3085

3086
                                //        Column sizes
3087
                                //  BD        144        Column size
3088
                                int columnSizesCount = this._objectReader.ReadBitLong();
161✔
3089
                                for (int i = 0; i < columnSizesCount; i++)
322!
3090
                                {
×
3091
                                        annotContext.ColumnSizes.Add(this._objectReader.ReadBitDouble());
×
3092
                                }
×
3093

3094
                                //        B        295        Word break
3095
                                annotContext.WordBreak = this._objectReader.ReadBit();
161✔
3096
                                //        B        Unknown
3097
                                this._objectReader.ReadBit();
161✔
3098
                                //        ELSE(Has text contents)
3099
                        }
161✔
3100
                        else if (annotContext.HasContentsBlock = this._objectReader.ReadBit())
×
3101
                        {
×
3102
                                //B        296        Has contents block
3103
                                //IF Has contents block
3104
                                //        H        341        AcDbBlockTableRecord handle (soft pointer)
3105
                                template.AnnotContextBlockRecordHandle = this.handleReference();
×
3106
                                //        3BD        14        Normal vector
3107
                                annotContext.BlockContentNormal = this._objectReader.Read3BitDouble();
×
3108
                                //        3BD        15        Location
3109
                                annotContext.BlockContentLocation = this._objectReader.Read3BitDouble();
×
3110
                                //        3BD        16        Scale vector
3111
                                annotContext.BlockContentScale = this._objectReader.Read3BitDouble();
×
3112
                                //        BD        46        Rotation (radians)
3113
                                annotContext.BlockContentRotation = this._objectReader.ReadBitDouble();
×
3114
                                //  CMC        93        Block color
3115
                                annotContext.BlockContentColor = this._objectReader.ReadCmColor();
×
3116
                                //        BD (16)        47        16 doubles containing the complete transformation
3117
                                //        matrix. Order of transformation is:
3118
                                //        - Rotation,
3119
                                //        - OCS to WCS (using normal vector),
3120
                                //        - Scaling (using scale vector)
3121
                                //        - Translation (using location)
3122
                                double m00 = this._objectReader.ReadBitDouble();
×
3123
                                double m10 = this._objectReader.ReadBitDouble();
×
3124
                                double m20 = this._objectReader.ReadBitDouble();
×
3125
                                double m30 = this._objectReader.ReadBitDouble();
×
3126

3127
                                double m01 = this._objectReader.ReadBitDouble();
×
3128
                                double m11 = this._objectReader.ReadBitDouble();
×
3129
                                double m21 = this._objectReader.ReadBitDouble();
×
3130
                                double m31 = this._objectReader.ReadBitDouble();
×
3131

3132
                                double m02 = this._objectReader.ReadBitDouble();
×
3133
                                double m12 = this._objectReader.ReadBitDouble();
×
3134
                                double m22 = this._objectReader.ReadBitDouble();
×
3135
                                double m32 = this._objectReader.ReadBitDouble();
×
3136

3137
                                double m03 = this._objectReader.ReadBitDouble();
×
3138
                                double m13 = this._objectReader.ReadBitDouble();
×
3139
                                double m23 = this._objectReader.ReadBitDouble();
×
3140
                                double m33 = this._objectReader.ReadBitDouble();
×
3141

3142
                                annotContext.TransformationMatrix = new Matrix4(
×
3143
                                                m00, m10, m20, m30,
×
3144
                                                m01, m11, m21, m31,
×
3145
                                                m02, m12, m22, m32,
×
3146
                                                m03, m13, m23, m33);
×
3147
                        }
×
3148
                        //END IF Has contents block
3149
                        //END IF Has text contents
3150

3151
                        //        3BD        110        Base point
3152
                        annotContext.BasePoint = this._objectReader.Read3BitDouble();
161✔
3153
                        //        3BD        111        Base direction
3154
                        annotContext.BaseDirection = this._objectReader.Read3BitDouble();
161✔
3155
                        //        3BD        112        Base vertical
3156
                        annotContext.BaseVertical = this._objectReader.Read3BitDouble();
161✔
3157
                        //        B        297        Is normal reversed?
3158
                        annotContext.NormalReversed = this._objectReader.ReadBit();
161✔
3159

3160
                        if (this.R2010Plus)
161✔
3161
                        {
89✔
3162
                                //        BS        273        Style top attachment
3163
                                annotContext.TextTopAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
89✔
3164
                                //        BS        272        Style bottom attachment
3165
                                annotContext.TextBottomAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
89✔
3166
                        }
89✔
3167

3168
                        return annotContext;
161✔
3169
                }
161✔
3170

3171
                private LeaderRoot readLeaderRoot(CadMLeaderTemplate template)
3172
                {
161✔
3173
                        LeaderRoot leaderRoot = new LeaderRoot();
161✔
3174

3175
                        //        B                290                Is content valid(ODA writes true)/DXF: Has Set Last Leader Line Point
3176
                        leaderRoot.ContentValid = this._objectReader.ReadBit();
161✔
3177
                        //        B                291                Unknown(ODA writes true)/DXF: Has Set Dogleg Vector
3178
                        leaderRoot.Unknown = this._objectReader.ReadBit();
161✔
3179
                        //        3BD                10                Connection point/DXF: Last Leader Line Point
3180
                        leaderRoot.ConnectionPoint = this._objectReader.Read3BitDouble();
161✔
3181
                        //        3BD                11                Direction/DXF: Dogleg vector
3182
                        leaderRoot.Direction = this._objectReader.Read3BitDouble();
161✔
3183

3184
                        //        Break start/end point pairs
3185
                        //        BL                Number of break start / end point pairs
3186
                        //        3BD                12                Break start point
3187
                        //        3BD                13                Break end point
3188
                        int breakStartEndPointCount = this._objectReader.ReadBitLong();
161✔
3189
                        for (int bsep = 0; bsep < breakStartEndPointCount; bsep++)
322!
3190
                        {
×
3191
                                leaderRoot.BreakStartEndPointsPairs.Add(new StartEndPointPair(
×
3192
                                        this._objectReader.Read3BitDouble(),
×
3193
                                        this._objectReader.Read3BitDouble()));
×
3194
                        }
×
3195

3196
                        //        BL                90                Leader index
3197
                        leaderRoot.LeaderIndex = this._objectReader.ReadBitLong();
161✔
3198
                        //        BD                40                Landing distance
3199
                        leaderRoot.LandingDistance = this._objectReader.ReadBitDouble();
161✔
3200

3201
                        //        Leader lines
3202
                        //        BL                Number of leader lines
3203
                        int leaderLineCount = this._objectReader.ReadBitLong();
161✔
3204
                        for (int ll = 0; ll < leaderLineCount; ll++)
644✔
3205
                        {
161✔
3206
                                leaderRoot.Lines.Add(this.readLeaderLine(template));
161✔
3207
                        }
161✔
3208

3209
                        if (this.R2010Plus)
161✔
3210
                        {
89✔
3211
                                //        BS        271        Attachment direction(0 = horizontal, 1 = vertical, default is 0)
3212
                                leaderRoot.TextAttachmentDirection = (TextAttachmentDirectionType)this._objectReader.ReadBitShort();
89✔
3213
                        }
89✔
3214

3215
                        return leaderRoot;
161✔
3216
                }
161✔
3217

3218
                private LeaderLine readLeaderLine(CadMLeaderTemplate template)
3219
                {
161✔
3220
                        LeaderLine leaderLine = new LeaderLine();
161✔
3221
                        CadMLeaderTemplate.LeaderLineSubTemplate leaderLineSubTemplate = new CadMLeaderTemplate.LeaderLineSubTemplate(leaderLine);
161✔
3222
                        template.LeaderLineSubTemplates.Add(leaderLineSubTemplate);
161✔
3223

3224
                        //        Points
3225
                        //        BL        -        Number of points
3226
                        int pointCount = this._objectReader.ReadBitLong();
161✔
3227
                        for (int p = 0; p < pointCount; p++)
644✔
3228
                        {
161✔
3229
                                //        3BD                10                Point
3230
                                leaderLine.Points.Add(this._objectReader.Read3BitDouble());
161✔
3231
                        }
161✔
3232

3233
                        //        Add optional Break Info (one or more)
3234
                        //        BL        Break info count
3235
                        leaderLine.BreakInfoCount = this._objectReader.ReadBitLong();
161✔
3236
                        if (leaderLine.BreakInfoCount > 0)
161!
3237
                        {
×
3238
                                //        BL        90                Segment index
3239
                                leaderLine.SegmentIndex = this._objectReader.ReadBitLong();
×
3240

3241
                                //        Start/end point pairs
3242
                                int startEndPointCount = this._objectReader.ReadBitLong();
×
3243
                                for (int sep = 0; sep < startEndPointCount; sep++)
×
3244
                                {
×
3245
                                        leaderLine.StartEndPoints.Add(new StartEndPointPair(
×
3246
                                                //        3BD        11        Start Point
×
3247
                                                this._objectReader.Read3BitDouble(),
×
3248
                                                //        3BD        12        End point
×
3249
                                                this._objectReader.Read3BitDouble()));
×
3250
                                }
×
3251
                        }
×
3252

3253
                        //        BL        91        Leader line index
3254
                        leaderLine.Index = this._objectReader.ReadBitLong();
161✔
3255

3256
                        if (this.R2010Plus)
161✔
3257
                        {
89✔
3258
                                //        BS        170        Leader type(0 = invisible leader, 1 = straight leader, 2 = spline leader)
3259
                                leaderLine.PathType = (MultiLeaderPathType)this._objectReader.ReadBitShort();
89✔
3260
                                //        CMC        92        Line color
3261
                                leaderLine.LineColor = this._objectReader.ReadCmColor();
89✔
3262
                                //        H        340        Line type handle(hard pointer)
3263
                                leaderLineSubTemplate.LineTypeHandle = this.handleReference();
89✔
3264
                                //        BL        171        Line weight
3265
                                leaderLine.LineWeight = (LineweightType)this._objectReader.ReadBitLong();
89✔
3266
                                //        BD        40        Arrow size
3267
                                leaderLine.ArrowheadSize = this._objectReader.ReadBitDouble();
89✔
3268
                                //        H        341        Arrow symbol handle(hard pointer)
3269
                                leaderLineSubTemplate.ArrowSymbolHandle = this.handleReference();
89✔
3270
                                //        BL        93        Override flags (1 = leader type, 2 = line color, 4 = line type, 8 = line weight, 16 = arrow size, 32 = arrow symbol(handle)
3271
                                leaderLine.OverrideFlags = (LeaderLinePropertOverrideFlags)this._objectReader.ReadBitLong();
89✔
3272
                        }
89✔
3273

3274
                        return leaderLine;
161✔
3275
                }
161✔
3276

3277
                private CadTemplate readMultiLeaderStyle()
3278
                {
172✔
3279
                        if (!this.R2010Plus)
172✔
3280
                        {
94✔
3281
                                return null;
94✔
3282
                        }
3283

3284
                        MultiLeaderStyle mLeaderStyle = new MultiLeaderStyle();
78✔
3285
                        CadMLeaderStyleTemplate template = new CadMLeaderStyleTemplate(mLeaderStyle);
78✔
3286

3287
                        this.readCommonNonEntityData(template);
78✔
3288

3289
                        //        BS        179        Version expected: 2
3290
                        var version = this._objectReader.ReadBitShort();
78✔
3291

3292
                        //        BS        170        Content type (see paragraph on LEADER for more details).
3293
                        mLeaderStyle.ContentType = (LeaderContentType)this._objectReader.ReadBitShort();
78✔
3294
                        //        BS        171        Draw multi-leader order (0 = draw content first, 1 = draw leader first)
3295
                        mLeaderStyle.MultiLeaderDrawOrder = (MultiLeaderDrawOrderType)this._objectReader.ReadBitShort();
78✔
3296
                        //        BS        172        Draw leader order (0 = draw leader head first, 1 = draw leader tail first)
3297
                        mLeaderStyle.LeaderDrawOrder = (LeaderDrawOrderType)this._objectReader.ReadBitShort();
78✔
3298
                        //        BL        90        Maximum number of points for leader
3299
                        mLeaderStyle.MaxLeaderSegmentsPoints = this._objectReader.ReadBitShort();
78✔
3300
                        //        BD        40        First segment angle (radians)
3301
                        mLeaderStyle.FirstSegmentAngleConstraint = this._objectReader.ReadBitDouble();
78✔
3302
                        //        BD        41        Second segment angle (radians)
3303
                        mLeaderStyle.SecondSegmentAngleConstraint = this._objectReader.ReadBitDouble();
78✔
3304
                        //        BS        173        Leader type (see paragraph on LEADER for more details).
3305
                        mLeaderStyle.PathType = (MultiLeaderPathType)this._objectReader.ReadBitShort();
78✔
3306
                        //        CMC        91        Leader line color
3307
                        mLeaderStyle.LineColor = this._mergedReaders.ReadCmColor();
78✔
3308
                        //        H        340        Leader line type handle (hard pointer)
3309
                        template.LeaderLineTypeHandle = this.handleReference();
78✔
3310
                        //        BL        92        Leader line weight
3311
                        mLeaderStyle.LeaderLineWeight = (LineweightType)this._objectReader.ReadBitLong();
78✔
3312
                        //        B        290        Is landing enabled?
3313
                        mLeaderStyle.EnableLanding = this._objectReader.ReadBit();
78✔
3314
                        //        BD        42        Landing gap
3315
                        mLeaderStyle.LandingGap = this._objectReader.ReadBitDouble();
78✔
3316
                        //        B        291        Auto include landing (is dog-leg enabled?)
3317
                        mLeaderStyle.EnableDogleg = this._objectReader.ReadBit();
78✔
3318
                        //        BD        43        Landing distance
3319
                        mLeaderStyle.LandingDistance = this._objectReader.ReadBitDouble();
78✔
3320
                        //        TV        3        Style description
3321
                        mLeaderStyle.Description = this._mergedReaders.ReadVariableText();
78✔
3322
                        //        H        341        Arrow head block handle (hard pointer)
3323
                        template.ArrowheadHandle = this.handleReference();
78✔
3324
                        //        BD        44        Arrow head size
3325
                        mLeaderStyle.ArrowheadSize = this._objectReader.ReadBitDouble();
78✔
3326
                        //        TV        300        Text default
3327
                        mLeaderStyle.DefaultTextContents = this._mergedReaders.ReadVariableText();
78✔
3328
                        //        H        342        Text style handle (hard pointer)
3329
                        template.MTextStyleHandle = this.handleReference();
78✔
3330
                        //        BS        174        Left attachment (see paragraph on LEADER for more details).
3331
                        mLeaderStyle.TextLeftAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
78✔
3332
                        //        BS        178        Right attachment (see paragraph on LEADER for more details).
3333
                        mLeaderStyle.TextRightAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
78✔
3334
                        if (this.R2010Plus)
78✔
3335
                        {//        IF IsNewFormat OR DXF file
78✔
3336
                         //        BS        175        Text angle type (see paragraph on LEADER for more details).
3337
                                mLeaderStyle.TextAngle = (TextAngleType)this._objectReader.ReadBitShort();
78✔
3338

3339
                        }   //        END IF IsNewFormat OR DXF file
78✔
3340
                                //        BS        176        Text alignment type
3341
                        mLeaderStyle.TextAlignment = (TextAlignmentType)this._objectReader.ReadBitShort();
78✔
3342
                        //        CMC        93        Text color
3343
                        mLeaderStyle.TextColor = this._mergedReaders.ReadCmColor();
78✔
3344
                        //        BD        45        Text height
3345
                        mLeaderStyle.TextHeight = this._objectReader.ReadBitDouble();
78✔
3346
                        //        B        292        Text frame enabled
3347
                        mLeaderStyle.TextFrame = this._objectReader.ReadBit();
78✔
3348
                        if (this.R2010Plus)
78✔
3349
                        {//        IF IsNewFormat OR DXF file
78✔
3350
                         //        B        297        Always align text left
3351
                                mLeaderStyle.TextAlignAlwaysLeft = this._objectReader.ReadBit();
78✔
3352
                        }//        END IF IsNewFormat OR DXF file
78✔
3353
                         //        BD        46        Align space
3354
                        mLeaderStyle.AlignSpace = this._objectReader.ReadBitDouble();
78✔
3355
                        //        H        343        Block handle (hard pointer)
3356
                        template.BlockContentHandle = this.handleReference();
78✔
3357
                        //        CMC        94        Block color
3358
                        mLeaderStyle.BlockContentColor = this._mergedReaders.ReadCmColor();
78✔
3359
                        //        3BD        47,49,140        Block scale vector
3360
                        mLeaderStyle.BlockContentScale = this._objectReader.Read3BitDouble();
78✔
3361
                        //        B        293        Is block scale enabled
3362
                        mLeaderStyle.EnableBlockContentScale = this._objectReader.ReadBit();
78✔
3363
                        //        BD        141        Block rotation (radians)
3364
                        mLeaderStyle.BlockContentRotation = this._objectReader.ReadBitDouble();
78✔
3365
                        //        B        294        Is block rotation enabled
3366
                        mLeaderStyle.EnableBlockContentRotation = this._objectReader.ReadBit();
78✔
3367
                        //        BS        177        Block connection type (0 = MLeader connects to the block extents, 1 = MLeader connects to the block base point)
3368
                        mLeaderStyle.BlockContentConnection = (BlockContentConnectionType)this._objectReader.ReadBitShort();
78✔
3369
                        //        BD        142        Scale factor
3370
                        mLeaderStyle.ScaleFactor = this._objectReader.ReadBitDouble();
78✔
3371
                        //        B        295        Property changed, meaning not totally clear
3372
                        //        might be set to true if something changed after loading,
3373
                        //        or might be used to trigger updates in dependent MLeaders.
3374
                        //        sequence seems to be different in DXF
3375
                        mLeaderStyle.OverwritePropertyValue = this._objectReader.ReadBit();
78✔
3376
                        //        B        296        Is annotative?
3377
                        mLeaderStyle.IsAnnotative = this._objectReader.ReadBit();
78✔
3378
                        //        BD        143        Break size
3379
                        mLeaderStyle.BreakGapSize = this._objectReader.ReadBitDouble();
78✔
3380

3381
                        //        BS        271        Attachment direction (see paragraph on LEADER for more details).
3382
                        mLeaderStyle.TextAttachmentDirection = (TextAttachmentDirectionType)this._objectReader.ReadBitShort();
78✔
3383
                        //        BS        273        Top attachment (see paragraph on LEADER for more details).
3384
                        mLeaderStyle.TextBottomAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
78✔
3385
                        //        BS        272        Bottom attachment (see paragraph on LEADER for more details).
3386
                        mLeaderStyle.TextTopAttachment = (TextAttachmentType)this._objectReader.ReadBitShort();
78✔
3387

3388
                        return template;
78✔
3389
                }
172✔
3390

3391
                private CadTemplate readTolerance()
3392
                {
231✔
3393
                        Tolerance tolerance = new Tolerance();
231✔
3394
                        CadToleranceTemplate template = new CadToleranceTemplate(tolerance);
231✔
3395

3396
                        //Common Entity Data
3397
                        this.readCommonEntityData(template);
231✔
3398

3399
                        //R13 - R14 Only:
3400
                        if (this.R13_14Only)
231✔
3401
                        {
33✔
3402
                                //Unknown short S
3403
                                short s = this._objectReader.ReadBitShort();
33✔
3404
                                //Height BD --
3405
                                double height = this._objectReader.ReadBitDouble();
33✔
3406
                                //Dimgap(?) BD dimgap at time of creation, *dimscale
3407
                                double dimscale = this._objectReader.ReadBitDouble();
33✔
3408
                        }
33✔
3409

3410
                        //Common:
3411
                        //Ins pt 3BD 10
3412
                        tolerance.InsertionPoint = this._objectReader.Read3BitDouble();
231✔
3413
                        //X direction 3BD 11
3414
                        tolerance.Direction = this._objectReader.Read3BitDouble();
231✔
3415
                        //Extrusion 3BD 210 etc.
3416
                        tolerance.Normal = this._objectReader.Read3BitDouble();
231✔
3417
                        //Text string BS 1
3418
                        tolerance.Text = this._textReader.ReadVariableText();
231✔
3419

3420
                        //Common Entity Handle Data
3421
                        //H DIMSTYLE(hard pointer)
3422
                        template.DimensionStyleHandle = this.handleReference();
231✔
3423

3424
                        return template;
231✔
3425
                }
231✔
3426

3427
                private CadTemplate readMLine()
3428
                {
231✔
3429
                        MLine mline = new MLine();
231✔
3430
                        CadMLineTemplate template = new CadMLineTemplate(mline);
231✔
3431

3432
                        this.readCommonEntityData(template);
231✔
3433

3434
                        //Scale BD 40
3435
                        mline.ScaleFactor = this._objectReader.ReadBitDouble();
231✔
3436
                        //Just EC top (0), bottom(2), or center(1)
3437
                        mline.Justification = (MLineJustification)this._objectReader.ReadByte();
231✔
3438
                        //Base point 3BD 10
3439
                        mline.StartPoint = this._objectReader.Read3BitDouble();
231✔
3440
                        //Extrusion 3BD 210 etc.
3441
                        mline.Normal = this._objectReader.Read3BitDouble();
231✔
3442

3443
                        //Openclosed BS open (1), closed(3)
3444
                        mline.Flags |= this._objectReader.ReadBitShort() == 3 ? MLineFlags.Closed : MLineFlags.Has;
231!
3445

3446
                        //Linesinstyle RC 73
3447
                        int nlines = (int)this._objectReader.ReadByte();
231✔
3448

3449
                        //Numverts BS 72
3450
                        int nverts = (int)this._objectReader.ReadBitShort();
231✔
3451
                        for (int i = 0; i < nverts; ++i)
2,310✔
3452
                        {
924✔
3453
                                MLine.Vertex vertex = new MLine.Vertex();
924✔
3454

3455
                                //vertex 3BD
3456
                                vertex.Position = this._objectReader.Read3BitDouble();
924✔
3457
                                //vertex direction 3BD
3458
                                vertex.Direction = this._objectReader.Read3BitDouble();
924✔
3459
                                //miter direction 3BD
3460
                                vertex.Miter = this._objectReader.Read3BitDouble();
924✔
3461

3462
                                for (int j = 0; j < nlines; ++j)
5,544✔
3463
                                {
1,848✔
3464
                                        MLine.Vertex.Segment element = new MLine.Vertex.Segment();
1,848✔
3465

3466
                                        //numsegparms BS
3467
                                        int nsegparms = (int)this._objectReader.ReadBitShort();
1,848✔
3468
                                        for (int k = 0; k < nsegparms; ++k)
11,396✔
3469
                                        {
3,850✔
3470
                                                //segparm BD segment parameter
3471
                                                element.Parameters.Add(this._objectReader.ReadBitDouble());
3,850✔
3472
                                        }
3,850✔
3473

3474
                                        //numareafillparms BS
3475
                                        int nfillparms = (int)this._objectReader.ReadBitShort();
1,848✔
3476
                                        for (int k = 0; k < nfillparms; ++k)
3,696!
3477
                                        {
×
3478
                                                //areafillparm BD area fill parameter
3479
                                                element.AreaFillParameters.Add(this._objectReader.ReadBitDouble());
×
3480
                                        }
×
3481

3482
                                        vertex.Segments.Add(element);
1,848✔
3483
                                }
1,848✔
3484

3485
                                mline.Vertices.Add(vertex);
924✔
3486
                        }
924✔
3487

3488
                        //H mline style oject handle (hard pointer)
3489
                        template.MLineStyleHandle = this.handleReference();
231✔
3490

3491
                        return template;
231✔
3492
                }
231✔
3493

3494
                private CadTemplate readBlockControlObject()
3495
                {
114✔
3496
                        CadBlockCtrlObjectTemplate template = new CadBlockCtrlObjectTemplate(
114✔
3497
                                new BlockRecordsTable());
114✔
3498

3499
                        this.readDocumentTable(template.CadObject, template);
114✔
3500

3501
                        //*MODEL_SPACE and *PAPER_SPACE(hard owner).
3502
                        template.ModelSpaceHandle = this.handleReference();
114✔
3503
                        template.PaperSpaceHandle = this.handleReference();
114✔
3504

3505
                        return template;
114✔
3506
                }
114✔
3507

3508
                private CadTemplate readBlockHeader()
3509
                {
1,323✔
3510
                        BlockRecord record = new BlockRecord();
1,323✔
3511
                        Block block = record.BlockEntity;
1,323✔
3512

3513
                        CadBlockRecordTemplate template = new CadBlockRecordTemplate(record);
1,323✔
3514
                        this._builder.BlockRecordTemplates.Add(template);
1,323✔
3515

3516
                        this.readCommonNonEntityData(template);
1,323✔
3517

3518
                        //Common:
3519
                        //Entry name TV 2
3520
                        //Warning: names ended with a number are not readed in this method
3521
                        string name = this._textReader.ReadVariableText();
1,323✔
3522
                        if (name.Equals(BlockRecord.ModelSpaceName, System.StringComparison.CurrentCultureIgnoreCase) ||
1,323✔
3523
                                name.Equals(BlockRecord.PaperSpaceName, System.StringComparison.CurrentCultureIgnoreCase))
1,323✔
3524
                                record.Name = name;
391✔
3525

3526
                        this.readXrefDependantBit(template.CadObject);
1,323✔
3527

3528
                        //Anonymous B 1 if this is an anonymous block (1 bit)
3529
                        if (this._objectReader.ReadBit())
1,323✔
3530
                                block.Flags |= BlockTypeFlags.Anonymous;
693✔
3531

3532
                        //Hasatts B 1 if block contains attdefs (2 bit)
3533
                        bool hasatts = this._objectReader.ReadBit();
1,323✔
3534

3535
                        //Blkisxref B 1 if block is xref (4 bit)
3536
                        if (this._objectReader.ReadBit())
1,323!
3537
                                block.Flags |= BlockTypeFlags.XRef;
×
3538

3539
                        //Xrefoverlaid B 1 if an overlaid xref (8 bit)
3540
                        if (this._objectReader.ReadBit())
1,323!
3541
                                block.Flags |= BlockTypeFlags.XRefOverlay;
×
3542

3543
                        //R2000+:
3544
                        if (this.R2000Plus)
1,323✔
3545
                        {
1,130✔
3546
                                //Loaded Bit B 0 indicates loaded for an xref
3547
                                this._objectReader.ReadBit();
1,130✔
3548
                        }
1,130✔
3549

3550
                        //R2004+:
3551
                        int nownedObjects = 0;
1,323✔
3552
                        if (this.R2004Plus
1,323✔
3553
                                && !block.Flags.HasFlag(BlockTypeFlags.XRef)
1,323✔
3554
                                && !block.Flags.HasFlag(BlockTypeFlags.XRefOverlay))
1,323✔
3555
                                //Owned Object Count BL Number of objects owned by this object.
3556
                                nownedObjects = this._objectReader.ReadBitLong();
945✔
3557

3558
                        //Common:
3559
                        //Base pt 3BD 10 Base point of block.
3560
                        block.BasePoint = this._objectReader.Read3BitDouble();
1,323✔
3561
                        //Xref pname TV 1 Xref pathname. That's right: DXF 1 AND 3!
3562
                        //3 1 appears in a tblnext/ search elist; 3 appears in an entget.
3563
                        block.XrefPath = this._textReader.ReadVariableText();
1,323✔
3564

3565
                        //R2000+:
3566
                        int insertCount = 0;
1,323✔
3567
                        if (this.R2000Plus)
1,323✔
3568
                        {
1,130✔
3569
                                //Insert Count RC A sequence of zero or more non-zero RC’s, followed by a terminating 0 RC.The total number of these indicates how many insert handles will be present.
3570
                                for (byte i = this._objectReader.ReadByte(); i != 0; i = this._objectReader.ReadByte())
3,064✔
3571
                                        ++insertCount;
402✔
3572

3573
                                //Block Description TV 4 Block description.
3574
                                block.Comments = this._textReader.ReadVariableText();
1,130✔
3575

3576
                                //Size of preview data BL Indicates number of bytes of data following.
3577
                                int n = this._objectReader.ReadBitLong();
1,130✔
3578
                                List<byte> data = new List<byte>();
1,130✔
3579
                                for (int index = 0; index < n; ++index)
548,212✔
3580
                                {
272,976✔
3581
                                        //Binary Preview Data N*RC 310
3582
                                        data.Add(this._objectReader.ReadByte());
272,976✔
3583
                                }
272,976✔
3584

3585
                                record.Preview = data.ToArray();
1,130✔
3586
                        }
1,130✔
3587

3588
                        //R2007+:
3589
                        if (this.R2007Plus)
1,323✔
3590
                        {
757✔
3591
                                //Insert units BS 70
3592
                                record.Units = (UnitsType)this._objectReader.ReadBitShort();
757✔
3593
                                //Explodable B 280
3594
                                record.IsExplodable = this._objectReader.ReadBit();
757✔
3595
                                //Block scaling RC 281
3596
                                record.CanScale = this._objectReader.ReadByte() > 0;
757✔
3597
                        }
757✔
3598

3599
                        //NULL(hard pointer)
3600
                        this.handleReference();
1,323✔
3601
                        //BLOCK entity. (hard owner)
3602
                        //Block begin object
3603
                        template.BeginBlockHandle = this.handleReference();
1,323✔
3604

3605
                        //R13-R2000:
3606
                        if (this._version >= ACadVersion.AC1012 && this._version <= ACadVersion.AC1015
1,323✔
3607
                                        && !block.Flags.HasFlag(BlockTypeFlags.XRef)
1,323✔
3608
                                        && !block.Flags.HasFlag(BlockTypeFlags.XRefOverlay))
1,323✔
3609
                        {
378✔
3610
                                //first entity in the def. (soft pointer)
3611
                                template.FirstEntityHandle = this.handleReference();
378✔
3612
                                //last entity in the def. (soft pointer)
3613
                                template.LastEntityHandle = this.handleReference();
378✔
3614
                        }
378✔
3615

3616
                        //R2004+:
3617
                        if (this.R2004Plus)
1,323✔
3618
                        {
945✔
3619
                                for (int i = 0; i < nownedObjects; ++i)
24,410✔
3620
                                        //H[ENTITY(hard owner)] Repeats “Owned Object Count” times.
3621
                                        template.OwnedObjectsHandlers.Add(this.handleReference());
11,260✔
3622
                        }
945✔
3623

3624
                        //Common:
3625
                        //ENDBLK entity. (hard owner)
3626
                        template.EndBlockHandle = this.handleReference();
1,323✔
3627

3628
                        //R2000+:
3629
                        if (this.R2000Plus)
1,323✔
3630
                        {
1,130✔
3631
                                //Insert Handles H N insert handles, where N corresponds to the number of insert count entries above(soft pointer).
3632
                                for (int i = 0; i < insertCount; ++i)
3,064✔
3633
                                {
402✔
3634
                                        //Entries        //TODO: necessary to store the insert handles??
3635
                                        template.InsertHandles.Add(this.handleReference());
402✔
3636
                                }
402✔
3637
                                //Layout Handle H(hard pointer)
3638
                                template.LayoutHandle = this.handleReference();
1,130✔
3639
                        }
1,130✔
3640

3641
                        return template;
1,323✔
3642
                }
1,323✔
3643

3644
                private CadTemplate readLayer()
3645
                {
1,436✔
3646
                        //Initialize the template with the default layer
3647
                        Layer layer = new Layer();
1,436✔
3648
                        CadLayerTemplate template = new CadLayerTemplate(layer);
1,436✔
3649

3650
                        this.readCommonNonEntityData(template);
1,436✔
3651

3652
                        //Common:
3653
                        //Entry name TV 2
3654
                        layer.Name = this._textReader.ReadVariableText();
1,436✔
3655

3656
                        this.readXrefDependantBit(template.CadObject);
1,436✔
3657

3658
                        //R13-R14 Only:
3659
                        if (this.R13_14Only)
1,436✔
3660
                        {
216✔
3661
                                //Frozen B 70 if frozen (1 bit)
3662
                                if (this._objectReader.ReadBit())
216✔
3663
                                        layer.Flags |= LayerFlags.Frozen;
11✔
3664

3665
                                //On B if on.
3666
                                layer.IsOn = this._objectReader.ReadBit();
216✔
3667

3668
                                //Frz in new B 70 if frozen by default in new viewports (2 bit)
3669
                                if (this._objectReader.ReadBit())
216✔
3670
                                        layer.Flags |= LayerFlags.FrozenNewViewports;
11✔
3671

3672
                                //Locked B 70 if locked (4 bit)
3673
                                if (this._objectReader.ReadBit())
216✔
3674
                                        layer.Flags |= LayerFlags.Locked;
11✔
3675
                        }
216✔
3676
                        //R2000+:
3677
                        if (this.R2000Plus)
1,436✔
3678
                        {
1,220✔
3679
                                //Values BS 70,290,370
3680
                                short values = this._objectReader.ReadBitShort();
1,220✔
3681

3682
                                //contains frozen (1 bit),
3683
                                if (((uint)values & 0b1) > 0)
1,220✔
3684
                                        layer.Flags |= LayerFlags.Frozen;
66✔
3685

3686
                                //on (2 bit)
3687
                                layer.IsOn = (values & 0b10) == 0;
1,220✔
3688

3689
                                //frozen by default in new viewports (4 bit)
3690
                                if (((uint)values & 0b100) > 0)
1,220✔
3691
                                        layer.Flags |= LayerFlags.FrozenNewViewports;
66✔
3692
                                //locked (8 bit)
3693
                                if (((uint)values & 0b1000) > 0)
1,220✔
3694
                                        layer.Flags |= LayerFlags.Locked;
66✔
3695

3696
                                //plotting flag (16 bit),
3697
                                layer.PlotFlag = ((uint)values & 0b10000) > 0;
1,220✔
3698

3699
                                //and lineweight (mask with 0x03E0)
3700
                                byte lineweight = (byte)((values & 0x3E0) >> 5);
1,220✔
3701
                                layer.LineWeight = CadUtils.ToValue(lineweight);
1,220✔
3702
                        }
1,220✔
3703

3704
                        //Common:
3705
                        //Color CMC 62
3706
                        layer.Color = this._mergedReaders.ReadCmColor();
1,436✔
3707

3708
                        //TODO: This is not the Layer control handle
3709
                        template.LayerControlHandle = this.handleReference();
1,436✔
3710
                        //Handle refs H Layer control (soft pointer)
3711
                        //[Reactors(soft pointer)]
3712
                        //xdicobjhandle(hard owner)
3713
                        //External reference block handle(hard pointer)
3714

3715
                        //R2000+:
3716
                        if (this.R2000Plus)
1,436✔
3717
                                //H 390 Plotstyle (hard pointer), by default points to PLACEHOLDER with handle 0x0f.
3718
                                template.PlotStyleHandle = this.handleReference();
1,220✔
3719

3720
                        //R2007+:
3721
                        if (this.R2007Plus)
1,436✔
3722
                        {
792✔
3723
                                //H 347 Material
3724
                                template.MaterialHandle = this.handleReference();
792✔
3725
                        }
792✔
3726

3727
                        //Common:
3728
                        //H 6 linetype (hard pointer)
3729
                        template.LineTypeHandle = this.handleReference();
1,436✔
3730

3731
                        if (this.R2013Plus)
1,436✔
3732
                        {
388✔
3733
                                //H Unknown handle (hard pointer). Always seems to be NULL.
3734
                                this.handleReference();
388✔
3735
                        }
388✔
3736

3737
                        return template;
1,436✔
3738
                }
1,436✔
3739

3740
                private CadTemplate readTextStyle()
3741
                {
508✔
3742
                        TextStyle style = new TextStyle();
508✔
3743
                        CadTableEntryTemplate<TextStyle> template = new CadTableEntryTemplate<TextStyle>(style);
508✔
3744

3745
                        this.readCommonNonEntityData(template);
508✔
3746

3747
                        //Common:
3748
                        //Entry name TV 2
3749
                        string name = this._textReader.ReadVariableText();
508✔
3750
                        if (!string.IsNullOrWhiteSpace(name))
508✔
3751
                        {
354✔
3752
                                style.Name = name;
354✔
3753
                        }
354✔
3754

3755
                        this.readXrefDependantBit(template.CadObject);
508✔
3756

3757
                        //shape file B 1 if a shape file rather than a font (1 bit)
3758
                        if (this._objectReader.ReadBit())
508✔
3759
                                style.Flags |= StyleFlags.IsShape;
154✔
3760
                        //Vertical B 1 if vertical (4 bit of flag)
3761
                        if (this._objectReader.ReadBit())
508!
3762
                                style.Flags |= StyleFlags.VerticalText;
×
3763
                        //Fixed height BD 40
3764
                        style.Height = this._objectReader.ReadBitDouble();
508✔
3765
                        //Width factor BD 41
3766
                        style.Width = this._objectReader.ReadBitDouble();
508✔
3767
                        //Oblique ang BD 50
3768
                        style.ObliqueAngle = this._objectReader.ReadBitDouble();
508✔
3769
                        //Generation RC 71 Generation flags (not bit-pair coded).
3770
                        style.MirrorFlag = (TextMirrorFlag)this._objectReader.ReadByte();
508✔
3771
                        //Last height BD 42
3772
                        style.LastHeight = this._objectReader.ReadBitDouble();
508✔
3773
                        //Font name TV 3
3774
                        style.Filename = this._textReader.ReadVariableText();
508✔
3775
                        //Bigfont name TV 4
3776
                        style.BigFontFilename = this._textReader.ReadVariableText();
508✔
3777

3778
                        ulong styleControl = this.handleReference();
508✔
3779

3780
                        return template;
508✔
3781
                }
508✔
3782

3783
                private CadTemplate readLTypeControlObject()
3784
                {
114✔
3785
                        CadTableTemplate<LineType> template = new CadTableTemplate<LineType>(
114✔
3786
                                new LineTypesTable());
114✔
3787

3788
                        this.readDocumentTable(template.CadObject, template);
114✔
3789

3790
                        //the linetypes, ending with BYLAYER and BYBLOCK.
3791
                        //all are soft owner references except BYLAYER and 
3792
                        //BYBLOCK, which are hard owner references.
3793
                        template.EntryHandles.Add(this.handleReference());
114✔
3794
                        template.EntryHandles.Add(this.handleReference());
114✔
3795

3796
                        return template;
114✔
3797
                }
114✔
3798

3799
                private CadTemplate readLType()
3800
                {
727✔
3801
                        LineType ltype = new LineType();
727✔
3802
                        CadLineTypeTemplate template = new CadLineTypeTemplate(ltype);
727✔
3803

3804
                        this.readCommonNonEntityData(template);
727✔
3805

3806
                        //Common:
3807
                        //Entry name TV 2
3808
                        ltype.Name = this._textReader.ReadVariableText();
727✔
3809

3810
                        this.readXrefDependantBit(template.CadObject);
727✔
3811

3812
                        //Description TV 3
3813
                        ltype.Description = this._textReader.ReadVariableText();
727✔
3814
                        //Pattern Len BD 40
3815
                        template.TotalLen = this._objectReader.ReadBitDouble();
727✔
3816
                        //Alignment RC 72 Always 'A'.
3817
                        ltype.Alignment = this._objectReader.ReadRawChar();
727✔
3818

3819
                        //Numdashes RC 73 The number of repetitions of the 49...74 data.
3820
                        int ndashes = this._objectReader.ReadByte();
727✔
3821
                        //Hold the text flag
3822
                        bool isText = false;
727✔
3823
                        for (int i = 0; i < ndashes; i++)
3,764✔
3824
                        {
1,155✔
3825
                                CadLineTypeTemplate.SegmentTemplate segment = new CadLineTypeTemplate.SegmentTemplate();
1,155✔
3826

3827
                                //Dash length BD 49 Dash or dot specifier.
3828
                                segment.Segment.Length = this._objectReader.ReadBitDouble();
1,155✔
3829
                                //Complex shapecode BS 75 Shape number if shapeflag is 2, or index into the string area if shapeflag is 4.
3830
                                segment.Segment.ShapeNumber = this._objectReader.ReadBitShort();
1,155✔
3831

3832
                                //X - offset RD 44 (0.0 for a simple dash.)
3833
                                //Y - offset RD 45(0.0 for a simple dash.)
3834
                                XY offset = new XY(this._objectReader.ReadDouble(), this._objectReader.ReadDouble());
1,155✔
3835
                                segment.Segment.Offset = offset;
1,155✔
3836

3837
                                //Scale BD 46 (1.0 for a simple dash.)
3838
                                segment.Segment.Scale = this._objectReader.ReadBitDouble();
1,155✔
3839
                                //Rotation BD 50 (0.0 for a simple dash.)
3840
                                segment.Segment.Rotation = this._objectReader.ReadBitDouble();
1,155✔
3841
                                //Shapeflag BS 74 bit coded:
3842
                                segment.Segment.Shapeflag = (LinetypeShapeFlags)this._objectReader.ReadBitShort();
1,155✔
3843

3844
                                if (segment.Segment.Shapeflag.HasFlag(LinetypeShapeFlags.Text))
1,155✔
3845
                                        isText = true;
77✔
3846

3847
                                //Add the segment to the type
3848
                                template.SegmentTemplates.Add(segment);
1,155✔
3849
                        }
1,155✔
3850

3851
                        //R2004 and earlier:
3852
                        if (this._version <= ACadVersion.AC1018)
727✔
3853
                        {
312✔
3854
                                //Strings area X 9 256 bytes of text area. The complex dashes that have text use this area via the 75-group indices. It's basically a pile of 0-terminated strings. First byte is always 0 for R13 and data starts at byte 1. In R14 it is not a valid data start from byte 0.
3855
                                //(The 9 - group is undocumented.)
3856
                                byte[] textarea = this._objectReader.ReadBytes(256);
312✔
3857
                                //TODO: Read the line type text area
3858
                        }
312✔
3859
                        //R2007+:
3860
                        if (this.R2007Plus && isText)
727✔
3861
                        {
44✔
3862
                                byte[] textarea = this._objectReader.ReadBytes(512);
44✔
3863
                                //TODO: Read the line type text area
3864
                        }
44✔
3865

3866
                        //Common:
3867
                        //Handle refs H Ltype control(soft pointer)
3868
                        //[Reactors (soft pointer)]
3869
                        //xdicobjhandle(hard owner)
3870
                        //External reference block handle(hard pointer)
3871
                        template.LtypeControlHandle = this.handleReference();
727✔
3872

3873
                        //340 shapefile for dash/shape (1 each) (hard pointer)
3874
                        for (int i = 0; i < ndashes; i++)
3,764✔
3875
                        {
1,155✔
3876
                                template.SegmentTemplates[i].StyleHandle = this.handleReference();
1,155✔
3877
                        }
1,155✔
3878

3879
                        return template;
727✔
3880
                }
727✔
3881

3882
                private CadTemplate readView()
3883
                {
77✔
3884
                        View view = new View();
77✔
3885
                        CadViewTemplate template = new CadViewTemplate(view);
77✔
3886

3887
                        this.readCommonNonEntityData(template);
77✔
3888

3889
                        //Common:
3890
                        //Entry name TV 2
3891
                        view.Name = this._textReader.ReadVariableText();
77✔
3892

3893
                        this.readXrefDependantBit(view);
77✔
3894

3895
                        //View height BD 40
3896
                        view.Height = this._objectReader.ReadBitDouble();
77✔
3897
                        //View width BD 41
3898
                        view.Width = this._objectReader.ReadBitDouble();
77✔
3899
                        //View center 2RD 10(Not bit - pair coded.)
3900
                        view.Center = this._objectReader.Read2RawDouble();
77✔
3901
                        //Target 3BD 12
3902
                        view.Target = this._objectReader.Read3BitDouble();
77✔
3903
                        //View dir 3BD 11 DXF doc suggests from target toward camera.
3904
                        view.Direction = this._objectReader.Read3BitDouble();
77✔
3905
                        //Twist angle BD 50 Radians
3906
                        view.Angle = this._objectReader.ReadBitDouble();
77✔
3907
                        //Lens length BD 42
3908
                        view.LensLength = this._objectReader.ReadBitDouble();
77✔
3909
                        //Front clip BD 43
3910
                        view.FrontClipping = this._objectReader.ReadBitDouble();
77✔
3911
                        //Back clip BD 44
3912
                        view.BackClipping = this._objectReader.ReadBitDouble();
77✔
3913

3914
                        //View mode X 71 4 bits: 0123
3915
                        //Note that only bits 0, 1, 2, and 4 of the 71 can be specified -- not bit 3 (8).
3916
                        //0 : 71's bit 0 (1)
3917
                        if (this._objectReader.ReadBit())
77!
3918
                                view.ViewMode |= ViewModeType.PerspectiveView;
×
3919
                        //1 : 71's bit 1 (2)
3920
                        if (this._objectReader.ReadBit())
77!
3921
                                view.ViewMode |= ViewModeType.FrontClipping;
×
3922
                        //2 : 71's bit 2 (4)
3923
                        if (this._objectReader.ReadBit())
77!
3924
                                view.ViewMode |= ViewModeType.BackClipping;
×
3925
                        //3 : OPPOSITE of 71's bit 4 (16)
3926
                        if (this._objectReader.ReadBit())
77✔
3927
                                view.ViewMode |= ViewModeType.FrontClippingZ;
77✔
3928

3929
                        //R2000+:
3930
                        if (this.R2000Plus)
77✔
3931
                        {
66✔
3932
                                //Render Mode RC 281
3933
                                view.RenderMode = (RenderMode)this._objectReader.ReadByte();
66✔
3934
                        }
66✔
3935

3936
                        //R2007+:
3937
                        if (this.R2007Plus)
77✔
3938
                        {
44✔
3939
                                //Use default lights B ? Default value is true
3940
                                this._mergedReaders.ReadBit();
44✔
3941
                                //Default lighting RC ? Default value is 1
3942
                                this._mergedReaders.ReadByte();
44✔
3943
                                //Brightness BD ? Default value is 0
3944
                                this._mergedReaders.ReadBitDouble();
44✔
3945
                                //Contrast BD ? Default value is 0
3946
                                this._mergedReaders.ReadBitDouble();
44✔
3947
                                //Abient color CMC? Default value is indexed color 250
3948
                                this._mergedReaders.ReadCmColor();
44✔
3949
                        }
44✔
3950

3951
                        //Common:
3952
                        //Pspace flag B 70 Bit 0(1) of the 70 - group.
3953
                        if (this._objectReader.ReadBit())
77!
3954
                                view.Flags |= (StandardFlags)0b1;
×
3955

3956
                        if (this.R2000Plus)
77✔
3957
                        {
66✔
3958
                                view.IsUcsAssociated = this._objectReader.ReadBit();
66✔
3959
                                if (view.IsUcsAssociated)
66✔
3960
                                {
66✔
3961
                                        //Origin 3BD 10 This and next 4 R2000 items are present only if 72 value is 1.
3962
                                        view.UcsOrigin = this._objectReader.Read3BitDouble();
66✔
3963
                                        //X-direction 3BD 11
3964
                                        view.UcsXAxis = this._objectReader.Read3BitDouble();
66✔
3965
                                        //Y-direction 3BD 12
3966
                                        view.UcsYAxis = this._objectReader.Read3BitDouble();
66✔
3967
                                        //Elevation BD 146
3968
                                        view.UcsElevation = this._objectReader.ReadBitDouble();
66✔
3969
                                        //OrthographicViewType BS 79
3970
                                        view.UcsOrthographicType = (OrthographicType)this._objectReader.ReadBitShort();
66✔
3971
                                }
66✔
3972
                        }
66✔
3973

3974
                        //Common:
3975
                        //Handle refs H view control object (soft pointer)
3976
                        this.handleReference();
77✔
3977

3978
                        //R2007+:
3979
                        if (this.R2007Plus)
77✔
3980
                        {
44✔
3981
                                //Camera plottable B 73
3982
                                view.IsPlottable = this._objectReader.ReadBit();
44✔
3983

3984
                                //Background handle H 332 soft pointer
3985
                                this.handleReference();
44✔
3986
                                //Visual style H 348 hard pointer
3987
                                this.handleReference();
44✔
3988
                                //Sun H 361 hard owner
3989
                                this.handleReference();
44✔
3990
                        }
44✔
3991

3992
                        if (this.R2000Plus && view.IsUcsAssociated)
77✔
3993
                        {
66✔
3994
                                //Base UCS Handle H 346 hard pointer
3995
                                template.UcsHandle = this.handleReference();
66✔
3996
                                //Named UCS Handle H 345 hard pointer
3997
                                template.NamedUcsHandle = this.handleReference();
66✔
3998
                        }
66✔
3999

4000
                        //R2007+:
4001
                        if (this.R2007Plus)
77✔
4002
                        {
44✔
4003
                                //Live section H 334 soft pointer
4004
                                this.handleReference();
44✔
4005
                        }
44✔
4006

4007
                        return template;
77✔
4008
                }
77✔
4009

4010
                private CadTemplate readUcs()
4011
                {
×
4012
                        UCS ucs = new UCS();
×
4013
                        CadTemplate<UCS> template = new CadTemplate<UCS>(ucs);
×
4014

4015
                        this.readCommonNonEntityData(template);
×
4016

4017
                        //Common:
4018
                        //Entry name TV 2
4019
                        ucs.Name = this._textReader.ReadVariableText();
×
4020

4021
                        this.readXrefDependantBit(ucs);
×
4022

4023
                        //Origin 3BD 10
4024
                        ucs.Origin = this._objectReader.Read3BitDouble();
×
4025
                        //X - direction 3BD 11
4026
                        ucs.XAxis = this._objectReader.Read3BitDouble();
×
4027
                        //Y - direction 3BD 12
4028
                        ucs.YAxis = this._objectReader.Read3BitDouble();
×
4029

4030
                        //R2000+:
4031
                        if (this.R2000Plus)
×
4032
                        {
×
4033
                                //Elevation BD 146
4034
                                ucs.Elevation = this._objectReader.ReadBitDouble();
×
4035
                                //OrthographicViewType BS 79        //dxf docs: 79        Always 0
4036
                                ucs.OrthographicViewType = (OrthographicType)this._objectReader.ReadBitShort();
×
4037
                                //OrthographicType BS 71
4038
                                ucs.OrthographicType = (OrthographicType)this._objectReader.ReadBitShort();
×
4039
                        }
×
4040

4041
                        //Common:
4042
                        //Handle refs H ucs control object (soft pointer)
4043
                        long control = (long)this.handleReference();
×
4044

4045
                        //R2000 +:
4046
                        if (this.R2000Plus)
×
4047
                        {
×
4048
                                //Base UCS Handle H 346 hard pointer
4049
                                long baseUcs = (long)this.handleReference();
×
4050
                                //Named UCS Handle H -hard pointer, not present in DXF
4051
                                long namedHandle = (long)this.handleReference();
×
4052
                        }
×
4053

4054
                        return template;
×
4055
                }
×
4056

4057
                private CadTemplate readVPort()
4058
                {
114✔
4059
                        VPort vport = new VPort();
114✔
4060
                        CadVPortTemplate template = new CadVPortTemplate(vport);
114✔
4061

4062
                        this.readCommonNonEntityData(template);
114✔
4063

4064
                        //Common:
4065
                        //Entry name TV 2
4066
                        vport.Name = this._textReader.ReadVariableText();
114✔
4067

4068
                        this.readXrefDependantBit(vport);
114✔
4069

4070
                        //View height BD 40
4071
                        vport.ViewHeight = this._objectReader.ReadBitDouble();
114✔
4072
                        //Aspect ratio BD 41 The number stored here is actually the aspect ratio times the view height (40),
4073
                        //so this number must be divided by the 40-value to produce the aspect ratio that entget gives.
4074
                        //(R13 quirk; R12 has just the aspect ratio.)
4075
                        vport.AspectRatio = this._objectReader.ReadBitDouble() / vport.ViewHeight;
114✔
4076
                        //View Center 2RD 12 DCS. (If it's plan view, add the view target (17) to get the WCS coordinates.
4077
                        //Careful! Sometimes you have to SAVE/OPEN to update the .dwg file.) Note that it's WSC in R12.
4078
                        vport.Center = this._objectReader.Read2RawDouble();
114✔
4079
                        //View target 3BD 17
4080
                        vport.Target = this._objectReader.Read3BitDouble();
114✔
4081
                        //View dir 3BD 16
4082
                        vport.Direction = this._objectReader.Read3BitDouble();
114✔
4083
                        //View twist BD 51
4084
                        vport.TwistAngle = this._objectReader.ReadBitDouble();
114✔
4085
                        //Lens length BD 42
4086
                        vport.LensLength = this._objectReader.ReadBitDouble();
114✔
4087
                        //Front clip BD 43
4088
                        vport.FrontClippingPlane = this._objectReader.ReadBitDouble();
114✔
4089
                        //Back clip BD 44
4090
                        vport.BackClippingPlane = this._objectReader.ReadBitDouble();
114✔
4091

4092
                        //View mode X 71 4 bits: 0123
4093
                        //Note that only bits 0, 1, 2, and 4 are given here; see UCSFOLLOW below for bit 3(8) of the 71.
4094
                        //0 : 71's bit 0 (1)
4095
                        if (this._objectReader.ReadBit())
114!
4096
                                vport.ViewMode |= ViewModeType.PerspectiveView;
×
4097
                        //1 : 71's bit 1 (2)
4098
                        if (this._objectReader.ReadBit())
114!
4099
                                vport.ViewMode |= ViewModeType.FrontClipping;
×
4100
                        //2 : 71's bit 2 (4)
4101
                        if (this._objectReader.ReadBit())
114!
4102
                                vport.ViewMode |= ViewModeType.BackClipping;
×
4103
                        //3 : OPPOSITE of 71's bit 4 (16)
4104
                        if (this._objectReader.ReadBit())
114✔
4105
                                vport.ViewMode |= ViewModeType.FrontClippingZ;
86✔
4106

4107
                        //R2000+:
4108
                        if (this.R2000Plus)
114✔
4109
                        {
96✔
4110
                                //Render Mode RC 281
4111
                                vport.RenderMode = (RenderMode)this._objectReader.ReadByte();
96✔
4112
                        }
96✔
4113

4114
                        //R2007+:
4115
                        if (this.R2007Plus)
114✔
4116
                        {
65✔
4117
                                //Use default lights B 292
4118
                                vport.UseDefaultLighting = this._objectReader.ReadBit();
65✔
4119
                                //Default lighting type RC 282
4120
                                vport.DefaultLighting = (DefaultLightingType)this._objectReader.ReadByte();
65✔
4121
                                //Brightness BD 141
4122
                                vport.Brightness = this._objectReader.ReadBitDouble();
65✔
4123
                                //Constrast BD 142
4124
                                vport.Contrast = this._objectReader.ReadBitDouble();
65✔
4125
                                //Ambient Color CMC 63
4126
                                vport.AmbientColor = this._mergedReaders.ReadCmColor();
65✔
4127
                        }
65✔
4128

4129
                        //Common:
4130
                        //Lower left 2RD 10 In fractions of screen width and height.
4131
                        vport.BottomLeft = this._objectReader.Read2RawDouble();
114✔
4132
                        //Upper right 2RD 11 In fractions of screen width and height.
4133
                        vport.TopRight = this._objectReader.Read2RawDouble();
114✔
4134

4135
                        //UCSFOLLOW B 71 UCSFOLLOW. Bit 3 (8) of the 71-group.
4136
                        if (this._objectReader.ReadBit())
114!
4137
                                vport.ViewMode |= ViewModeType.Follow;
×
4138

4139
                        //Circle zoom BS 72 Circle zoom percent.
4140
                        vport.CircleZoomPercent = this._objectReader.ReadBitShort();
114✔
4141

4142
                        //Fast zoom B 73
4143
                        this._objectReader.ReadBit();
114✔
4144

4145
                        //UCSICON X 74 2 bits: 01
4146
                        //0 : 74's bit 0 (1)
4147
                        if (this._objectReader.ReadBit())
114✔
4148
                                vport.UcsIconDisplay = UscIconType.OnLower;
114✔
4149
                        //1 : 74's bit 1 (2)
4150
                        if (this._objectReader.ReadBit())
114✔
4151
                                vport.UcsIconDisplay = UscIconType.OnOrigin;
114✔
4152

4153
                        //Grid on/off B 76
4154
                        vport.ShowGrid = this._objectReader.ReadBit();
114✔
4155
                        //Grd spacing 2RD 15
4156
                        vport.GridSpacing = this._objectReader.Read2RawDouble();
114✔
4157
                        //Snap on/off B 75
4158
                        vport.SnapOn = this._objectReader.ReadBit();
114✔
4159

4160
                        //Snap style B 77
4161
                        vport.IsometricSnap = this._objectReader.ReadBit();
114✔
4162

4163
                        //Snap isopair BS 78
4164
                        vport.SnapIsoPair = this._objectReader.ReadBitShort();
114✔
4165
                        //Snap rot BD 50
4166
                        vport.SnapRotation = this._objectReader.ReadBitDouble();
114✔
4167
                        //Snap base 2RD 13
4168
                        vport.SnapBasePoint = this._objectReader.Read2RawDouble();
114✔
4169
                        //Snp spacing 2RD 14
4170
                        vport.SnapSpacing = this._objectReader.Read2RawDouble();
114✔
4171

4172
                        //R2000+:
4173
                        if (this.R2000Plus)
114✔
4174
                        {
96✔
4175
                                //Unknown B
4176
                                this._objectReader.ReadBit();
96✔
4177

4178
                                //UCS per Viewport B 71
4179
                                bool ucsPerViewport = this._objectReader.ReadBit();
96✔
4180
                                //UCS Origin 3BD 110
4181
                                vport.Origin = this._objectReader.Read3BitDouble();
96✔
4182
                                //UCS X Axis 3BD 111
4183
                                vport.XAxis = this._objectReader.Read3BitDouble();
96✔
4184
                                //UCS Y Axis 3BD 112
4185
                                vport.YAxis = this._objectReader.Read3BitDouble();
96✔
4186
                                //UCS Elevation BD 146
4187
                                vport.Elevation = this._objectReader.ReadBitDouble();
96✔
4188
                                //UCS Orthographic type BS 79
4189
                                vport.OrthographicType = (OrthographicType)this._objectReader.ReadBitShort();
96✔
4190
                        }
96✔
4191

4192
                        //R2007+:
4193
                        if (this.R2007Plus)
114✔
4194
                        {
65✔
4195
                                //Grid flags BS 60
4196
                                vport.GridFlags = (GridFlags)this._objectReader.ReadBitShort();
65✔
4197
                                //Grid major BS 61
4198
                                vport.MinorGridLinesPerMajorGridLine = this._objectReader.ReadBitShort();
65✔
4199
                        }
65✔
4200

4201
                        //Common:
4202
                        //Handle refs H Vport control(soft pointer)
4203
                        //[Reactors(soft pointer)]
4204
                        //xdicobjhandle(hard owner)
4205
                        //External reference block handle(hard pointer)
4206
                        template.VportControlHandle = this.handleReference();
114✔
4207

4208
                        //R2007+:
4209
                        if (this.R2007Plus)
114✔
4210
                        {
65✔
4211
                                //Background handle H 332 soft pointer
4212
                                template.BackgroundHandle = this.handleReference();
65✔
4213
                                //Visual Style handle H 348 hard pointer
4214
                                template.StyleHandle = this.handleReference();
65✔
4215
                                //Sun handle H 361 hard owner
4216
                                template.SunHandle = this.handleReference();
65✔
4217
                        }
65✔
4218

4219
                        //R2000+:
4220
                        if (this.R2000Plus)
114✔
4221
                        {
96✔
4222
                                //Named UCS Handle H 345 hard pointer
4223
                                template.NamedUcsHandle = this.handleReference();
96✔
4224
                                //Base UCS Handle H 346 hard pointer
4225
                                template.BaseUcsHandle = this.handleReference();
96✔
4226
                        }
96✔
4227

4228
                        return template;
114✔
4229
                }
114✔
4230

4231
                private CadTemplate readAppId()
4232
                {
1,412✔
4233
                        AppId appId = new AppId();
1,412✔
4234
                        CadTemplate template = new CadTemplate<AppId>(appId);
1,412✔
4235

4236
                        this.readCommonNonEntityData(template);
1,412✔
4237

4238
                        appId.Name = this._textReader.ReadVariableText();
1,412✔
4239

4240
                        this.readXrefDependantBit(appId);
1,412✔
4241

4242
                        //Unknown RC 71 Undoc'd 71-group; doesn't even appear in DXF or an entget if it's 0.
4243
                        this._objectReader.ReadByte();
1,412✔
4244

4245
                        //External reference block handle(hard pointer)        ??
4246
                        this.handleReference();
1,412✔
4247

4248
                        return template;
1,412✔
4249
                }
1,412✔
4250

4251
                private CadTemplate readDimStyle()
4252
                {
285✔
4253
                        DimensionStyle dimStyle = new DimensionStyle();
285✔
4254
                        CadDimensionStyleTemplate template = new CadDimensionStyleTemplate(dimStyle);
285✔
4255

4256
                        this.readCommonNonEntityData(template);
285✔
4257

4258
                        //Common:
4259
                        //Entry name TV 2
4260
                        string name = this._textReader.ReadVariableText();
285✔
4261
                        if (name.IsNullOrEmpty())
285!
4262
                        {
×
4263
                                this._builder.Notify($"[DimensionStyle] with handle {dimStyle.Handle} does not have a name assigned", NotificationType.Warning);
×
4264
                        }
×
4265
                        else
4266
                        {
285✔
4267
                                dimStyle.Name = name;
285✔
4268
                        }
285✔
4269

4270
                        this.readXrefDependantBit(dimStyle);
285✔
4271

4272
                        //R13 & R14 Only:
4273
                        if (this.R13_14Only)
285✔
4274
                        {
42✔
4275
                                //DIMTOL B 71
4276
                                dimStyle.GenerateTolerances = this._objectReader.ReadBit();
42✔
4277
                                //DIMLIM B 72
4278
                                dimStyle.LimitsGeneration = this._objectReader.ReadBit();
42✔
4279
                                //DIMTIH B 73
4280
                                dimStyle.TextOutsideHorizontal = this._objectReader.ReadBit();
42✔
4281
                                //DIMTOH B 74
4282
                                dimStyle.SuppressFirstExtensionLine = this._objectReader.ReadBit();
42✔
4283
                                //DIMSE1 B 75
4284
                                dimStyle.SuppressSecondExtensionLine = this._objectReader.ReadBit();
42✔
4285
                                //DIMSE2 B 76
4286
                                dimStyle.TextInsideHorizontal = this._objectReader.ReadBit();
42✔
4287
                                //DIMALT B 170
4288
                                dimStyle.AlternateUnitDimensioning = this._objectReader.ReadBit();
42✔
4289
                                //DIMTOFL B 172
4290
                                dimStyle.TextOutsideExtensions = this._objectReader.ReadBit();
42✔
4291
                                //DIMSAH B 173
4292
                                dimStyle.SeparateArrowBlocks = this._objectReader.ReadBit();
42✔
4293
                                //DIMTIX B 174
4294
                                dimStyle.TextInsideExtensions = this._objectReader.ReadBit();
42✔
4295
                                //DIMSOXD B 175
4296
                                dimStyle.SuppressOutsideExtensions = this._objectReader.ReadBit();
42✔
4297
                                //DIMALTD RC 171
4298
                                dimStyle.AlternateUnitDecimalPlaces = this._objectReader.ReadByte();
42✔
4299
                                //DIMZIN RC 78
4300
                                dimStyle.ZeroHandling = (ZeroHandling)this._objectReader.ReadRawChar();
42✔
4301
                                //DIMSD1 B 281
4302
                                dimStyle.SuppressFirstDimensionLine = this._objectReader.ReadBit();
42✔
4303
                                //DIMSD2 B 282
4304
                                dimStyle.SuppressSecondDimensionLine = this._objectReader.ReadBit();
42✔
4305
                                //DIMTOLJ RC 283
4306
                                dimStyle.ToleranceAlignment = (ToleranceAlignment)this._objectReader.ReadRawChar();
42✔
4307
                                //DIMJUST RC 280
4308
                                dimStyle.TextHorizontalAlignment = (DimensionTextHorizontalAlignment)this._objectReader.ReadByte();
42✔
4309
                                //DIMFIT RC 287
4310
                                dimStyle.DimensionFit = (short)this._objectReader.ReadRawChar();
42✔
4311
                                //DIMUPT B 288
4312
                                dimStyle.CursorUpdate = this._objectReader.ReadBit();
42✔
4313
                                //DIMTZIN RC 284
4314
                                dimStyle.ToleranceZeroHandling = (ZeroHandling)this._objectReader.ReadByte();
42✔
4315
                                //DIMALTZ RC 285
4316
                                dimStyle.AlternateUnitZeroHandling = (ZeroHandling)this._objectReader.ReadByte();
42✔
4317
                                //DIMALTTZ RC 286
4318
                                dimStyle.AlternateUnitToleranceZeroHandling = (ZeroHandling)this._objectReader.ReadByte();
42✔
4319
                                //DIMTAD RC 77
4320
                                dimStyle.TextVerticalAlignment = (DimensionTextVerticalAlignment)this._objectReader.ReadByte();
42✔
4321
                                //DIMUNIT BS 270
4322
                                dimStyle.DimensionUnit = this._objectReader.ReadBitShort();
42✔
4323
                                //DIMAUNIT BS 275
4324
                                dimStyle.AngularUnit = (AngularUnitFormat)this._objectReader.ReadBitShort();
42✔
4325
                                //DIMDEC BS 271
4326
                                dimStyle.DecimalPlaces = this._objectReader.ReadBitShort();
42✔
4327
                                //DIMTDEC BS 272
4328
                                dimStyle.ToleranceDecimalPlaces = this._objectReader.ReadBitShort();
42✔
4329
                                //DIMALTU BS 273
4330
                                dimStyle.AlternateUnitFormat = (LinearUnitFormat)this._objectReader.ReadBitShort();
42✔
4331
                                //DIMALTTD BS 274
4332
                                dimStyle.AlternateUnitToleranceDecimalPlaces = this._objectReader.ReadBitShort();
42✔
4333
                                //DIMSCALE BD 40
4334
                                dimStyle.ScaleFactor = this._objectReader.ReadBitDouble();
42✔
4335
                                //DIMASZ BD 41
4336
                                dimStyle.ArrowSize = this._objectReader.ReadBitDouble();
42✔
4337
                                //DIMEXO BD 42
4338
                                dimStyle.ExtensionLineOffset = this._objectReader.ReadBitDouble();
42✔
4339
                                //DIMDLI BD 43
4340
                                dimStyle.DimensionLineIncrement = this._objectReader.ReadBitDouble();
42✔
4341
                                //DIMEXE BD 44
4342
                                dimStyle.ExtensionLineExtension = this._objectReader.ReadBitDouble();
42✔
4343
                                //DIMRND BD 45
4344
                                dimStyle.Rounding = this._objectReader.ReadBitDouble();
42✔
4345
                                //DIMDLE BD 46
4346
                                dimStyle.DimensionLineExtension = this._objectReader.ReadBitDouble();
42✔
4347
                                //DIMTP BD 47
4348
                                dimStyle.PlusTolerance = this._objectReader.ReadBitDouble();
42✔
4349
                                //DIMTM BD 48
4350
                                dimStyle.MinusTolerance = this._objectReader.ReadBitDouble();
42✔
4351
                                //DIMTXT BD 140
4352
                                dimStyle.TextHeight = this._objectReader.ReadBitDouble();
42✔
4353
                                //DIMCEN BD 141
4354
                                dimStyle.CenterMarkSize = this._objectReader.ReadBitDouble();
42✔
4355
                                //DIMTSZ BD 142
4356
                                dimStyle.TickSize = this._objectReader.ReadBitDouble();
42✔
4357
                                //DIMALTF BD 143
4358
                                dimStyle.AlternateUnitScaleFactor = this._objectReader.ReadBitDouble();
42✔
4359
                                //DIMLFAC BD 144
4360
                                dimStyle.LinearScaleFactor = this._objectReader.ReadBitDouble();
42✔
4361
                                //DIMTVP BD 145
4362
                                dimStyle.TextVerticalPosition = this._objectReader.ReadBitDouble();
42✔
4363
                                //DIMTFAC BD 146
4364
                                dimStyle.ToleranceScaleFactor = this._objectReader.ReadBitDouble();
42✔
4365
                                //DIMGAP BD 147
4366
                                dimStyle.DimensionLineGap = this._objectReader.ReadBitDouble();
42✔
4367
                                //DIMPOST T 3
4368
                                dimStyle.PostFix = this._textReader.ReadVariableText();
42✔
4369
                                //DIMAPOST T 4
4370
                                dimStyle.AlternateDimensioningSuffix = this._textReader.ReadVariableText();
42✔
4371

4372
                                //DIMBLK T 5
4373
                                template.DIMBL_Name = this._textReader.ReadVariableText();
42✔
4374
                                //DIMBLK1 T 6
4375
                                template.DIMBLK1_Name = this._textReader.ReadVariableText();
42✔
4376
                                //DIMBLK2 T 7
4377
                                template.DIMBLK2_Name = this._textReader.ReadVariableText();
42✔
4378

4379
                                //DIMCLRD BS 176
4380
                                dimStyle.DimensionLineColor = this._objectReader.ReadColorByIndex();
42✔
4381
                                //DIMCLRE BS 177
4382
                                dimStyle.ExtensionLineColor = this._objectReader.ReadColorByIndex();
42✔
4383
                                //DIMCLRT BS 178
4384
                                dimStyle.TextColor = this._objectReader.ReadColorByIndex();
42✔
4385
                        }
42✔
4386

4387
                        //R2000+:
4388
                        if (this.R2000Plus)
285✔
4389
                        {
243✔
4390
                                //DIMPOST TV 3
4391
                                dimStyle.PostFix = this._textReader.ReadVariableText();
243✔
4392
                                //DIMAPOST TV 4
4393
                                dimStyle.AlternateDimensioningSuffix = this._textReader.ReadVariableText();
243✔
4394
                                //DIMSCALE BD 40
4395
                                dimStyle.ScaleFactor = this._objectReader.ReadBitDouble();
243✔
4396
                                //DIMASZ BD 41
4397
                                dimStyle.ArrowSize = this._objectReader.ReadBitDouble();
243✔
4398
                                //DIMEXO BD 42
4399
                                dimStyle.ExtensionLineOffset = this._objectReader.ReadBitDouble();
243✔
4400
                                //DIMDLI BD 43
4401
                                dimStyle.DimensionLineIncrement = this._objectReader.ReadBitDouble();
243✔
4402
                                //DIMEXE BD 44
4403
                                dimStyle.ExtensionLineExtension = this._objectReader.ReadBitDouble();
243✔
4404
                                //DIMRND BD 45
4405
                                dimStyle.Rounding = this._objectReader.ReadBitDouble();
243✔
4406
                                //DIMDLE BD 46
4407
                                dimStyle.DimensionLineExtension = this._objectReader.ReadBitDouble();
243✔
4408
                                //DIMTP BD 47
4409
                                dimStyle.PlusTolerance = this._objectReader.ReadBitDouble();
243✔
4410
                                //DIMTM BD 48
4411
                                dimStyle.MinusTolerance = this._objectReader.ReadBitDouble();
243✔
4412
                        }
243✔
4413

4414
                        //R2007+:
4415
                        if (this.R2007Plus)
285✔
4416
                        {
166✔
4417
                                //DIMFXL BD 49
4418
                                dimStyle.FixedExtensionLineLength = this._objectReader.ReadBitDouble();
166✔
4419
                                //DIMJOGANG BD 50
4420
                                dimStyle.JoggedRadiusDimensionTransverseSegmentAngle = this._objectReader.ReadBitDouble();
166✔
4421
                                //DIMTFILL BS 69
4422
                                dimStyle.TextBackgroundFillMode = (DimensionTextBackgroundFillMode)this._objectReader.ReadBitShort();
166✔
4423
                                //DIMTFILLCLR CMC 70
4424
                                dimStyle.TextBackgroundColor = this._mergedReaders.ReadCmColor();
166✔
4425
                        }
166✔
4426

4427
                        //R2000+:
4428
                        if (this.R2000Plus)
285✔
4429
                        {
243✔
4430
                                //DIMTOL B 71
4431
                                dimStyle.GenerateTolerances = this._objectReader.ReadBit();
243✔
4432
                                //DIMLIM B 72
4433
                                dimStyle.LimitsGeneration = this._objectReader.ReadBit();
243✔
4434
                                //DIMTIH B 73
4435
                                dimStyle.TextInsideHorizontal = this._objectReader.ReadBit();
243✔
4436
                                //DIMTOH B 74
4437
                                dimStyle.TextOutsideHorizontal = this._objectReader.ReadBit();
243✔
4438
                                //DIMSE1 B 75
4439
                                dimStyle.SuppressFirstExtensionLine = this._objectReader.ReadBit();
243✔
4440
                                //DIMSE2 B 76
4441
                                dimStyle.SuppressSecondExtensionLine = this._objectReader.ReadBit();
243✔
4442
                                //DIMTAD BS 77
4443
                                dimStyle.TextVerticalAlignment = (DimensionTextVerticalAlignment)this._objectReader.ReadBitShort();
243✔
4444
                                //DIMZIN BS 78
4445
                                dimStyle.ZeroHandling = (ZeroHandling)this._objectReader.ReadBitShort();
243✔
4446
                                //DIMAZIN BS 79
4447
                                dimStyle.AngularZeroHandling = (ZeroHandling)this._objectReader.ReadBitShort();
243✔
4448
                        }
243✔
4449

4450
                        //R2007 +:
4451
                        if (this.R2007Plus)
285✔
4452
                                //DIMARCSYM BS 90
4453
                                dimStyle.ArcLengthSymbolPosition = (ArcLengthSymbolPosition)this._objectReader.ReadBitShort();
166✔
4454

4455
                        //R2000 +:
4456
                        if (this.R2000Plus)
285✔
4457
                        {
243✔
4458
                                //DIMTXT BD 140
4459
                                dimStyle.TextHeight = this._objectReader.ReadBitDouble();
243✔
4460
                                //DIMCEN BD 141
4461
                                dimStyle.CenterMarkSize = this._objectReader.ReadBitDouble();
243✔
4462
                                //DIMTSZ BD 142
4463
                                dimStyle.TickSize = this._objectReader.ReadBitDouble();
243✔
4464
                                //DIMALTF BD 143
4465
                                dimStyle.AlternateUnitScaleFactor = this._objectReader.ReadBitDouble();
243✔
4466
                                //DIMLFAC BD 144
4467
                                dimStyle.LinearScaleFactor = this._objectReader.ReadBitDouble();
243✔
4468
                                //DIMTVP BD 145
4469
                                dimStyle.TextVerticalPosition = this._objectReader.ReadBitDouble();
243✔
4470
                                //DIMTFAC BD 146
4471
                                dimStyle.ToleranceScaleFactor = this._objectReader.ReadBitDouble();
243✔
4472
                                //DIMGAP BD 147
4473
                                dimStyle.DimensionLineGap = this._objectReader.ReadBitDouble();
243✔
4474
                                //DIMALTRND BD 148
4475
                                dimStyle.AlternateUnitRounding = this._objectReader.ReadBitDouble();
243✔
4476
                                //DIMALT B 170
4477
                                dimStyle.AlternateUnitDimensioning = this._objectReader.ReadBit();
243✔
4478
                                //DIMALTD BS 171
4479
                                dimStyle.AlternateUnitDecimalPlaces = this._objectReader.ReadBitShort();
243✔
4480
                                //DIMTOFL B 172
4481
                                dimStyle.TextOutsideExtensions = this._objectReader.ReadBit();
243✔
4482
                                //DIMSAH B 173
4483
                                dimStyle.SeparateArrowBlocks = this._objectReader.ReadBit();
243✔
4484
                                //DIMTIX B 174
4485
                                dimStyle.TextInsideExtensions = this._objectReader.ReadBit();
243✔
4486
                                //DIMSOXD B 175
4487
                                dimStyle.SuppressOutsideExtensions = this._objectReader.ReadBit();
243✔
4488
                                //DIMCLRD BS 176
4489
                                dimStyle.DimensionLineColor = this._mergedReaders.ReadCmColor();
243✔
4490
                                //DIMCLRE BS 177
4491
                                dimStyle.ExtensionLineColor = this._mergedReaders.ReadCmColor();
243✔
4492
                                //DIMCLRT BS 178
4493
                                dimStyle.TextColor = this._mergedReaders.ReadCmColor();
243✔
4494
                                //DIMADEC BS 179
4495
                                dimStyle.AngularDimensionDecimalPlaces = this._objectReader.ReadBitShort();
243✔
4496
                                //DIMDEC BS 271
4497
                                dimStyle.DecimalPlaces = this._objectReader.ReadBitShort();
243✔
4498
                                //DIMTDEC BS 272
4499
                                dimStyle.ToleranceDecimalPlaces = this._objectReader.ReadBitShort();
243✔
4500
                                //DIMALTU BS 273
4501
                                dimStyle.AlternateUnitFormat = (LinearUnitFormat)this._objectReader.ReadBitShort();
243✔
4502
                                //DIMALTTD BS 274
4503
                                dimStyle.AlternateUnitToleranceDecimalPlaces = this._objectReader.ReadBitShort();
243✔
4504
                                //DIMAUNIT BS 275
4505
                                dimStyle.AngularUnit = (AngularUnitFormat)this._objectReader.ReadBitShort();
243✔
4506
                                //DIMFRAC BS 276
4507
                                dimStyle.FractionFormat = (FractionFormat)this._objectReader.ReadBitShort();
243✔
4508
                                //DIMLUNIT BS 277
4509
                                dimStyle.LinearUnitFormat = (LinearUnitFormat)this._objectReader.ReadBitShort();
243✔
4510
                                //DIMDSEP BS 278
4511
                                dimStyle.DecimalSeparator = (char)this._objectReader.ReadBitShort();
243✔
4512
                                //DIMTMOVE BS 279
4513
                                dimStyle.TextMovement = (TextMovement)this._objectReader.ReadBitShort();
243✔
4514
                                //DIMJUST BS 280
4515
                                dimStyle.TextHorizontalAlignment = (DimensionTextHorizontalAlignment)this._objectReader.ReadBitShort();
243✔
4516
                                //DIMSD1 B 281
4517
                                dimStyle.SuppressFirstDimensionLine = this._objectReader.ReadBit();
243✔
4518
                                //DIMSD2 B 282
4519
                                dimStyle.SuppressSecondDimensionLine = this._objectReader.ReadBit();
243✔
4520
                                //DIMTOLJ BS 283
4521
                                dimStyle.ToleranceAlignment = (ToleranceAlignment)this._objectReader.ReadBitShort();
243✔
4522
                                //DIMTZIN BS 284
4523
                                dimStyle.ToleranceZeroHandling = (ZeroHandling)this._objectReader.ReadBitShort();
243✔
4524
                                //DIMALTZ BS 285
4525
                                dimStyle.AlternateUnitZeroHandling = (ZeroHandling)this._objectReader.ReadBitShort();
243✔
4526
                                //DIMALTTZ BS 286
4527
                                dimStyle.AlternateUnitToleranceZeroHandling = (ZeroHandling)this._objectReader.ReadBitShort();
243✔
4528
                                //DIMUPT B 288
4529
                                dimStyle.CursorUpdate = this._objectReader.ReadBit();
243✔
4530
                                //DIMFIT BS 287
4531
                                dimStyle.DimensionFit = this._objectReader.ReadBitShort();
243✔
4532
                        }
243✔
4533

4534
                        //R2007+:
4535
                        if (this.R2007Plus)
285✔
4536
                                //DIMFXLON B 290
4537
                                dimStyle.IsExtensionLineLengthFixed = this._objectReader.ReadBit();
166✔
4538

4539
                        //R2010+:
4540
                        if (this.R2010Plus)
285✔
4541
                        {
128✔
4542
                                //DIMTXTDIRECTION B 295
4543
                                dimStyle.TextDirection = this._objectReader.ReadBit() ? TextDirection.RightToLeft : TextDirection.LeftToRight;
128!
4544
                                //DIMALTMZF BD ?
4545
                                dimStyle.AltMzf = this._objectReader.ReadBitDouble();
128✔
4546
                                //DIMALTMZS T ?
4547
                                dimStyle.AltMzs = this._textReader.ReadVariableText();
128✔
4548
                                //DIMMZF BD ?
4549
                                dimStyle.Mzf = this._objectReader.ReadBitDouble();
128✔
4550
                                //DIMMZS T ?
4551
                                dimStyle.Mzs = this._textReader.ReadVariableText();
128✔
4552
                        }
128✔
4553

4554
                        //R2000+:
4555
                        if (this.R2000Plus)
285✔
4556
                        {
243✔
4557
                                //DIMLWD BS 371
4558
                                dimStyle.DimensionLineWeight = (LineweightType)this._objectReader.ReadBitShort();
243✔
4559
                                //DIMLWE BS 372
4560
                                dimStyle.ExtensionLineWeight = (LineweightType)this._objectReader.ReadBitShort();
243✔
4561
                        }
243✔
4562

4563
                        //Common:
4564
                        //Unknown B 70 Seems to set the 0 - bit(1) of the 70 - group.
4565
                        this._objectReader.ReadBit();
285✔
4566

4567
                        //External reference block handle(hard pointer)
4568
                        long block = (long)this.handleReference();
285✔
4569

4570
                        //340 shapefile(DIMTXSTY)(hard pointer)
4571
                        template.TextStyleHandle = this.handleReference();
285✔
4572

4573
                        //R2000+:
4574
                        if (this.R2000Plus)
285✔
4575
                        {
243✔
4576
                                //341 leader block(DIMLDRBLK) (hard pointer)
4577
                                template.DIMLDRBLK = this.handleReference();
243✔
4578
                                //342 dimblk(DIMBLK)(hard pointer)
4579
                                template.DIMBLK = this.handleReference();
243✔
4580
                                //343 dimblk1(DIMBLK1)(hard pointer)
4581
                                template.DIMBLK1 = this.handleReference();
243✔
4582
                                //344 dimblk2(DIMBLK2)(hard pointer)
4583
                                template.DIMBLK2 = this.handleReference();
243✔
4584
                        }
243✔
4585

4586
                        //R2007+:
4587
                        if (this.R2007Plus)
285✔
4588
                        {
166✔
4589
                                //345 dimltype(hard pointer)
4590
                                template.Dimltype = this.handleReference();
166✔
4591
                                //346 dimltex1(hard pointer)
4592
                                template.Dimltex1 = this.handleReference();
166✔
4593
                                //347 dimltex2(hard pointer)
4594
                                template.Dimltex2 = this.handleReference();
166✔
4595
                        }
166✔
4596

4597
                        return template;
285✔
4598
                }
285✔
4599

4600
                private CadTemplate readViewportEntityControl()
4601
                {
23✔
4602
                        return null;
23✔
4603

4604
                        DwgViewportEntityControlTemplate template = new DwgViewportEntityControlTemplate();
4605

4606
                        this.readCommonNonEntityData(template);
4607

4608
                        //Common:
4609
                        //Numentries BL 70
4610
                        int numentries = this._objectReader.ReadBitLong();
4611
                        for (int i = 0; i < numentries; ++i)
4612
                                //Handle refs H NULL(soft pointer)        xdicobjhandle(hard owner)        the apps(soft owner)
4613
                                template.EntryHandles.Add(this.handleReference());
4614

4615
                        return template;
4616
                }
23✔
4617

4618
                private CadTemplate readViewportEntityHeader()
4619
                {
44✔
4620
                        //Viewport viewport = new Viewport();
4621
                        //DwgViewportTemplate template = new DwgViewportTemplate(viewport);
4622

4623
                        //this.readCommonNonEntityData(template);
4624

4625
                        ////Common:
4626
                        ////Entry name TV 2
4627
                        //viewport.StyleSheetName = this._textReader.ReadVariableText();
4628

4629
                        //this.readXrefDependantBit(viewport);
4630

4631
                        ////1 flag B The 1 bit of the 70 group
4632
                        //this._objectReader.ReadBit();
4633

4634
                        ////Handle refs H viewport entity control (soft pointer)
4635
                        //this.handleReference();
4636
                        ////xdicobjhandle (hard owner)
4637
                        //this.handleReference();
4638
                        ////External reference block handle (hard pointer)
4639
                        //this.handleReference();
4640

4641
                        //TODO: transform the viewport ent into the viewport
4642

4643
                        return null;
44✔
4644
                }
44✔
4645

4646
                private CadTemplate readGroup()
4647
                {
154✔
4648
                        Group group = new Group();
154✔
4649
                        DwgGroupTemplate template = new DwgGroupTemplate(group);
154✔
4650

4651
                        this.readCommonNonEntityData(template);
154✔
4652

4653
                        //Str TV name of group
4654
                        group.Description = this._textReader.ReadVariableText();
154✔
4655

4656
                        //Unnamed BS 1 if group has no name
4657
                        group.IsUnnamed = this._objectReader.ReadBitShort() > 0;
154✔
4658
                        //Selectable BS 1 if group selectable
4659
                        group.Selectable = this._objectReader.ReadBitShort() > 0;
154✔
4660

4661
                        //Numhandles BL # objhandles in this group
4662
                        int numhandles = this._objectReader.ReadBitLong();
154✔
4663
                        for (int index = 0; index < numhandles; ++index)
2,156✔
4664
                                //the entries in the group(hard pointer)
4665
                                template.Handles.Add(this.handleReference());
924✔
4666

4667
                        return template;
154✔
4668
                }
154✔
4669

4670
                private CadTemplate readMLineStyle()
4671
                {
114✔
4672
                        MLineStyle mlineStyle = new MLineStyle();
114✔
4673
                        CadMLineStyleTemplate template = new CadMLineStyleTemplate(mlineStyle);
114✔
4674

4675
                        this.readCommonNonEntityData(template);
114✔
4676

4677
                        //Common:
4678
                        //Name TV Name of this style
4679
                        mlineStyle.Name = this._textReader.ReadVariableText();
114✔
4680
                        //Desc TV Description of this style
4681
                        mlineStyle.Description = this._textReader.ReadVariableText();
114✔
4682
                        //Flags BS A short which reconstitutes the mlinestyle flags as defined in DXF.
4683
                        //Here are the bits as they relate to DXF:
4684
                        /*
4685
                         DWG bit goes with DXF bit
4686
                                1                                2
4687
                                2                                1
4688
                                16                                16
4689
                                32                                64
4690
                                64                                32
4691
                                256                                256
4692
                                512                                1024
4693
                                1024                        512
4694
                         */
4695
                        short flags = this._objectReader.ReadBitShort();
114✔
4696
                        if (((uint)flags & 1U) > 0U)
114!
4697
                                mlineStyle.Flags |= MLineStyleFlags.DisplayJoints;
×
4698
                        if (((uint)flags & 2U) > 0U)
114!
4699
                                mlineStyle.Flags |= MLineStyleFlags.FillOn;
×
4700
                        if (((uint)flags & 16U) > 0U)
114!
4701
                                mlineStyle.Flags |= MLineStyleFlags.StartSquareCap;
×
4702
                        if (((uint)flags & 32U) > 0U)
114!
4703
                                mlineStyle.Flags |= MLineStyleFlags.StartRoundCap;
×
4704
                        if (((uint)flags & 64U) > 0U)
114!
4705
                                mlineStyle.Flags |= MLineStyleFlags.StartInnerArcsCap;
×
4706
                        if (((uint)flags & 256U) > 0U)
114!
4707
                                mlineStyle.Flags |= MLineStyleFlags.EndSquareCap;
×
4708
                        if (((uint)flags & 512U) > 0U)
114!
4709
                                mlineStyle.Flags |= MLineStyleFlags.EndRoundCap;
×
4710
                        if (((uint)flags & 1024U) > 0U)
114!
4711
                                mlineStyle.Flags |= MLineStyleFlags.EndInnerArcsCap;
×
4712

4713
                        //fillcolor CMC Fill color for this style
4714
                        mlineStyle.FillColor = this._mergedReaders.ReadCmColor();
114✔
4715
                        //startang BD Start angle
4716
                        mlineStyle.StartAngle = this._objectReader.ReadBitDouble();
114✔
4717
                        //endang BD End angle
4718
                        mlineStyle.EndAngle = this._objectReader.ReadBitDouble();
114✔
4719

4720
                        //linesinstyle RC Number of lines in this style
4721
                        int nlines = this._objectReader.ReadByte();
114✔
4722
                        for (int i = 0; i < nlines; ++i)
572✔
4723
                        {
172✔
4724
                                MLineStyle.Element element = new MLineStyle.Element();
172✔
4725
                                CadMLineStyleTemplate.ElementTemplate elementTemplate = new CadMLineStyleTemplate.ElementTemplate(element);
172✔
4726

4727
                                //Offset BD Offset of this segment
4728
                                element.Offset = this._objectReader.ReadBitDouble();
172✔
4729
                                //Color CMC Color of this segment
4730
                                element.Color = this._mergedReaders.ReadCmColor();
172✔
4731

4732
                                //R2018+:
4733
                                if (this.R2018Plus)
172✔
4734
                                {
30✔
4735
                                        //Line type handle H Line type handle (hard pointer)
4736
                                        elementTemplate.LineTypeHandle = this.handleReference();
30✔
4737
                                }
30✔
4738
                                //Before R2018:
4739
                                else
4740
                                {
142✔
4741
                                        //Ltindex BS Linetype index (yes, index)
4742
                                        elementTemplate.LinetypeIndex = this._objectReader.ReadBitShort();
142✔
4743
                                }
142✔
4744

4745
                                template.ElementTemplates.Add(elementTemplate);
172✔
4746
                                mlineStyle.Elements.Add(element);
172✔
4747
                        }
172✔
4748

4749
                        return template;
114✔
4750
                }
114✔
4751

4752
                private CadTemplate readLWPolyline()
4753
                {
847✔
4754
                        LwPolyline lwPolyline = new LwPolyline();
847✔
4755
                        CadEntityTemplate template = new CadEntityTemplate(lwPolyline);
847✔
4756

4757
                        try
4758
                        {
847✔
4759
                                this.readCommonEntityData(template);
847✔
4760

4761
                                //B : bytes containing the LWPOLYLINE entity data.
4762
                                //This excludes the common entity data.
4763
                                //More specifically: it starts at the LWPOLYLINE flags (BS), and ends with the width array (BD).
4764

4765
                                short flags = this._objectReader.ReadBitShort();
847✔
4766
                                if ((flags & 0x100) != 0)
847!
4767
                                        lwPolyline.Flags |= LwPolylineFlags.Plinegen;
×
4768
                                if ((flags & 0x200) != 0)
847✔
4769
                                        lwPolyline.Flags |= LwPolylineFlags.Closed;
539✔
4770

4771
                                if ((flags & 0x4u) != 0)
847✔
4772
                                {
77✔
4773
                                        lwPolyline.ConstantWidth = this._objectReader.ReadBitDouble();
77✔
4774
                                }
77✔
4775

4776
                                if ((flags & 0x8u) != 0)
847!
4777
                                {
×
4778
                                        lwPolyline.Elevation = this._objectReader.ReadBitDouble();
×
4779
                                }
×
4780

4781
                                if ((flags & 0x2u) != 0)
847!
4782
                                {
×
4783
                                        lwPolyline.Thickness = this._objectReader.ReadBitDouble();
×
4784
                                }
×
4785

4786
                                if ((flags & (true ? 1u : 0u)) != 0)
847!
4787
                                {
×
4788
                                        lwPolyline.Normal = this._objectReader.Read3BitDouble();
×
4789
                                }
×
4790

4791
                                int nvertices = this._objectReader.ReadBitLong();
847✔
4792
                                int nbulges = 0;
847✔
4793

4794
                                if (((uint)flags & 0x10) != 0)
847✔
4795
                                {
231✔
4796
                                        nbulges = this._objectReader.ReadBitLong();
231✔
4797
                                }
231✔
4798

4799
                                int nids = 0;
847✔
4800
                                if (((uint)flags & 0x400) != 0)
847!
4801
                                {
×
4802
                                        nids = this._objectReader.ReadBitLong();
×
4803
                                }
×
4804

4805
                                int ndiffwidth = 0;
847✔
4806
                                if (((uint)flags & 0x20) != 0)
847✔
4807
                                {
154✔
4808
                                        ndiffwidth = this._objectReader.ReadBitLong();
154✔
4809
                                }
154✔
4810

4811
                                if (this.R13_14Only)
847✔
4812
                                {
121✔
4813
                                        for (int i = 0; i < nvertices; i++)
1,430✔
4814
                                        {
594✔
4815
                                                Vertex2D v = new Vertex2D();
594✔
4816
                                                XY loc = this._objectReader.Read2RawDouble();
594✔
4817
                                                lwPolyline.Vertices.Add(new LwPolyline.Vertex(loc));
594✔
4818
                                        }
594✔
4819
                                }
121✔
4820

4821
                                if (this.R2000Plus && nvertices > 0)
847✔
4822
                                {
726✔
4823
                                        XY loc = this._objectReader.Read2RawDouble();
726✔
4824
                                        lwPolyline.Vertices.Add(new LwPolyline.Vertex(loc));
726✔
4825
                                        for (int j = 1; j < nvertices; j++)
7,128✔
4826
                                        {
2,838✔
4827
                                                loc = this._objectReader.Read2BitDoubleWithDefault(loc);
2,838✔
4828
                                                lwPolyline.Vertices.Add(new LwPolyline.Vertex(loc));
2,838✔
4829
                                        }
2,838✔
4830
                                }
726✔
4831

4832
                                for (int k = 0; k < nbulges; k++)
4,620✔
4833
                                {
1,463✔
4834
                                        lwPolyline.Vertices[k].Bulge = this._objectReader.ReadBitDouble();
1,463✔
4835
                                }
1,463✔
4836

4837
                                for (int l = 0; l < nids; l++)
1,694!
4838
                                {
×
4839
                                        lwPolyline.Vertices[l].Id = this._objectReader.ReadBitLong();
×
4840
                                }
×
4841

4842
                                for (int m = 0; m < ndiffwidth; m++)
3,234✔
4843
                                {
770✔
4844
                                        LwPolyline.Vertex vertex = lwPolyline.Vertices[m];
770✔
4845
                                        vertex.StartWidth = this._objectReader.ReadBitDouble();
770✔
4846
                                        vertex.EndWidth = this._objectReader.ReadBitDouble();
770✔
4847
                                }
770✔
4848
                        }
847✔
4849
                        catch (System.Exception ex)
×
4850
                        {
×
4851
                                this._builder.Notify($"Exception while reading LwPolyline: {ex.GetType().FullName}", NotificationType.Error, ex);
×
4852
                                return template;
×
4853
                        }
4854

4855
                        return template;
847✔
4856
                }
847✔
4857

4858
                private CadTemplate readHatch()
4859
                {
308✔
4860
                        Hatch hatch = new Hatch();
308✔
4861
                        CadHatchTemplate template = new CadHatchTemplate(hatch);
308✔
4862

4863
                        this.readCommonEntityData(template);
308✔
4864

4865
                        //R2004+:
4866
                        if (this.R2004Plus)
308✔
4867
                        {
220✔
4868
                                //Is Gradient Fill BL 450 Non-zero indicates a gradient fill is used.
4869
                                hatch.GradientColor.Enabled = this._objectReader.ReadBitLong() != 0;
220✔
4870

4871
                                //Reserved BL 451
4872
                                hatch.GradientColor.Reserved = this._objectReader.ReadBitLong();
220✔
4873
                                //Gradient Angle BD 460
4874
                                hatch.GradientColor.Angle = this._objectReader.ReadBitDouble();
220✔
4875
                                //Gradient Shift BD 461
4876
                                hatch.GradientColor.Shift = this._objectReader.ReadBitDouble();
220✔
4877
                                //Single Color Grad.BL 452
4878
                                hatch.GradientColor.IsSingleColorGradient = (uint)this._objectReader.ReadBitLong() > 0U;
220✔
4879
                                //Gradient Tint BD 462
4880
                                hatch.GradientColor.ColorTint = this._objectReader.ReadBitDouble();
220✔
4881

4882
                                //# of Gradient Colors BL 453
4883
                                int ncolors = this._objectReader.ReadBitLong();
220✔
4884
                                for (int i = 0; i < ncolors; ++i)
1,320✔
4885
                                {
440✔
4886
                                        GradientColor color = new GradientColor();
440✔
4887

4888
                                        //Gradient Value double BD 463
4889
                                        color.Value = this._objectReader.ReadBitDouble();
440✔
4890
                                        //RGB Color
4891
                                        color.Color = this._mergedReaders.ReadCmColor();
440✔
4892

4893
                                        hatch.GradientColor.Colors.Add(color);
440✔
4894
                                }
440✔
4895

4896
                                //Gradient Name TV 470
4897
                                hatch.GradientColor.Name = this._textReader.ReadVariableText();
220✔
4898
                        }
220✔
4899

4900
                        //Common:
4901
                        //Z coord BD 30 X, Y always 0.0
4902
                        hatch.Elevation = this._objectReader.ReadBitDouble();
308✔
4903
                        //Extrusion 3BD 210
4904
                        hatch.Normal = this._objectReader.Read3BitDouble();
308✔
4905
                        //Name TV 2 name of hatch
4906
                        hatch.Pattern = new HatchPattern(this._textReader.ReadVariableText());
308✔
4907
                        //Solidfill B 70 1 if solidfill, else 0
4908
                        hatch.IsSolid = this._objectReader.ReadBit();
308✔
4909
                        //Associative B 71 1 if associative, else 0
4910
                        hatch.IsAssociative = this._objectReader.ReadBit();
308✔
4911

4912
                        //Numpaths BL 91 Number of paths enclosing the hatch
4913
                        int npaths = this._objectReader.ReadBitLong();
308✔
4914
                        bool hasDerivedBoundary = false;
308✔
4915

4916
                        #region Read the boundary path data
4917

4918
                        for (int i = 0; i < npaths; i++)
1,232✔
4919
                        {
308✔
4920
                                CadHatchTemplate.CadBoundaryPathTemplate pathTemplate = new CadHatchTemplate.CadBoundaryPathTemplate();
308✔
4921

4922
                                //Pathflag BL 92 Path flag
4923
                                var flags = (BoundaryPathFlags)this._objectReader.ReadBitLong();
308✔
4924

4925
                                pathTemplate.Path.Flags = flags;
308✔
4926

4927
                                if (pathTemplate.Path.Flags.HasFlag(BoundaryPathFlags.Derived))
308!
4928
                                        hasDerivedBoundary = true;
×
4929

4930
                                if (!flags.HasFlag(BoundaryPathFlags.Polyline))
308!
4931
                                {
308✔
4932
                                        //Numpathsegs BL 93 number of segments in this path
4933
                                        int nsegments = this._objectReader.ReadBitLong();
308✔
4934
                                        for (int j = 0; j < nsegments; ++j)
3,080✔
4935
                                        {
1,232✔
4936
                                                //pathtypestatus RC 72 type of path
4937
                                                Hatch.BoundaryPath.EdgeType pathTypeStatus = (Hatch.BoundaryPath.EdgeType)this._objectReader.ReadByte();
1,232✔
4938
                                                switch (pathTypeStatus)
1,232!
4939
                                                {
4940
                                                        case Hatch.BoundaryPath.EdgeType.Line:
4941
                                                                pathTemplate.Path.Edges.Add(new Hatch.BoundaryPath.Line
1,232✔
4942
                                                                {
1,232✔
4943
                                                                        //pt0 2RD 10 first endpoint
1,232✔
4944
                                                                        Start = this._objectReader.Read2RawDouble(),
1,232✔
4945
                                                                        //pt1 2RD 11 second endpoint
1,232✔
4946
                                                                        End = this._objectReader.Read2RawDouble()
1,232✔
4947
                                                                });
1,232✔
4948
                                                                break;
1,232✔
4949
                                                        case Hatch.BoundaryPath.EdgeType.CircularArc:
4950
                                                                pathTemplate.Path.Edges.Add(new Hatch.BoundaryPath.Arc
×
4951
                                                                {
×
4952
                                                                        //pt0 2RD 10 center
×
4953
                                                                        Center = this._objectReader.Read2RawDouble(),
×
4954
                                                                        //radius BD 40 radius
×
4955
                                                                        Radius = this._objectReader.ReadBitDouble(),
×
4956
                                                                        //startangle BD 50 start angle
×
4957
                                                                        StartAngle = this._objectReader.ReadBitDouble(),
×
4958
                                                                        //endangle BD 51 endangle
×
4959
                                                                        EndAngle = this._objectReader.ReadBitDouble(),
×
4960
                                                                        //isccw B 73 1 if counter clockwise, otherwise 0
×
4961
                                                                        CounterClockWise = this._objectReader.ReadBit()
×
4962
                                                                });
×
4963
                                                                break;
×
4964
                                                        case Hatch.BoundaryPath.EdgeType.EllipticArc:
4965
                                                                pathTemplate.Path.Edges.Add(new Hatch.BoundaryPath.Ellipse
×
4966
                                                                {
×
4967
                                                                        //pt0 2RD 10 center
×
4968
                                                                        Center = this._objectReader.Read2RawDouble(),
×
4969
                                                                        //endpoint 2RD 11 endpoint of major axis
×
4970
                                                                        MajorAxisEndPoint = this._objectReader.Read2RawDouble(),
×
4971
                                                                        //minormajoratio BD 40 ratio of minor to major axis
×
4972
                                                                        MinorToMajorRatio = this._objectReader.ReadBitDouble(),
×
4973
                                                                        //startangle BD 50 start angle
×
4974
                                                                        StartAngle = this._objectReader.ReadBitDouble(),
×
4975
                                                                        //endangle BD 51 endangle
×
4976
                                                                        EndAngle = this._objectReader.ReadBitDouble(),
×
4977
                                                                        //isccw B 73 1 if counter clockwise, otherwise 0
×
4978
                                                                        CounterClockWise = this._objectReader.ReadBit()
×
4979
                                                                });
×
4980
                                                                break;
×
4981
                                                        case Hatch.BoundaryPath.EdgeType.Spline:
4982
                                                                Hatch.BoundaryPath.Spline splineEdge = new Hatch.BoundaryPath.Spline();
×
4983

4984
                                                                //degree BL 94 degree of the spline
4985
                                                                splineEdge.Degree = this._objectReader.ReadBitLong();
×
4986
                                                                //isrational B 73 1 if rational(has weights), else 0
4987
                                                                splineEdge.Rational = this._objectReader.ReadBit();
×
4988
                                                                //isperiodic B 74 1 if periodic, else 0
4989
                                                                splineEdge.Periodic = this._objectReader.ReadBit();
×
4990

4991
                                                                //numknots BL 95 number of knots
4992
                                                                int numknots = this._objectReader.ReadBitLong();
×
4993
                                                                //numctlpts BL 96 number of control points
4994
                                                                int numctlpts = this._objectReader.ReadBitLong();
×
4995

4996
                                                                for (int k = 0; k < numknots; ++k)
×
4997
                                                                        //knot BD 40 knot value
4998
                                                                        splineEdge.Knots.Add(this._objectReader.ReadBitDouble());
×
4999

5000
                                                                for (int p = 0; p < numctlpts; ++p)
×
5001
                                                                {
×
5002
                                                                        //pt0 2RD 10 control point
5003
                                                                        var cp = this._objectReader.Read2RawDouble();
×
5004

5005
                                                                        double wheight = 0;
×
5006
                                                                        if (splineEdge.Rational)
×
5007
                                                                                //weight BD 40 weight
5008
                                                                                wheight = this._objectReader.ReadBitDouble();
×
5009

5010
                                                                        //Add the control point and its wheight
5011
                                                                        splineEdge.ControlPoints.Add(new XYZ(cp.X, cp.Y, wheight));
×
5012
                                                                }
×
5013

5014
                                                                //R24:
5015
                                                                if (this.R2010Plus)
×
5016
                                                                {
×
5017
                                                                        //Numfitpoints BL 97 number of fit points
5018
                                                                        int nfitPoints = this._objectReader.ReadBitLong();
×
5019
                                                                        if (nfitPoints > 0)
×
5020
                                                                        {
×
5021
                                                                                for (int fp = 0; fp < nfitPoints; ++fp)
×
5022
                                                                                {
×
5023
                                                                                        //Fitpoint 2RD 11
5024
                                                                                        splineEdge.FitPoints.Add(this._objectReader.Read2RawDouble());
×
5025
                                                                                }
×
5026

5027
                                                                                //Start tangent 2RD 12
5028
                                                                                splineEdge.StartTangent = this._objectReader.Read2RawDouble();
×
5029
                                                                                //End tangent 2RD 13
5030
                                                                                splineEdge.EndTangent = this._objectReader.Read2RawDouble();
×
5031
                                                                        }
×
5032
                                                                }
×
5033

5034
                                                                //Add the spline
5035
                                                                pathTemplate.Path.Edges.Add(splineEdge);
×
5036
                                                                break;
×
5037
                                                }
5038
                                        }
1,232✔
5039
                                }
308✔
5040
                                else    //POLYLINE PATH
5041
                                {
×
5042
                                        Hatch.BoundaryPath.Polyline pline = new Hatch.BoundaryPath.Polyline();
×
5043
                                        //bulgespresent B 72 bulges are present if 1
5044
                                        bool bulgespresent = this._objectReader.ReadBit();
×
5045
                                        //closed B 73 1 if closed
5046
                                        pline.IsClosed = this._objectReader.ReadBit();
×
5047

5048
                                        //numpathsegs BL 91 number of path segments
5049
                                        int numpathsegs = this._objectReader.ReadBitLong();
×
5050
                                        for (int index = 0; index < numpathsegs; ++index)
×
5051
                                        {
×
5052
                                                //pt0 2RD 10 point on polyline
5053
                                                XY vertex = this._objectReader.Read2RawDouble();
×
5054
                                                double bulge = 0;
×
5055
                                                if (bulgespresent)
×
5056
                                                {
×
5057
                                                        //bulge BD 42 bulge
5058
                                                        bulge = this._objectReader.ReadBitDouble();
×
5059
                                                }
×
5060

5061
                                                //Add the vertex
5062
                                                pline.Vertices.Add(new XYZ(vertex.X, vertex.Y, bulge));
×
5063
                                        }
×
5064

5065
                                        pathTemplate.Path.Edges.Add(pline);
×
5066
                                }
×
5067

5068
                                //numboundaryobjhandles BL 97 Number of boundary object handles for this path
5069
                                int numboundaryobjhandles = this._objectReader.ReadBitLong();
308✔
5070
                                for (int h = 0; h < numboundaryobjhandles; h++)
1,232✔
5071
                                {
308✔
5072
                                        //boundaryhandle H 330 boundary handle(soft pointer)
5073
                                        pathTemplate.Handles.Add(this.handleReference());
308✔
5074
                                }
308✔
5075

5076
                                template.PathTempaltes.Add(pathTemplate);
308✔
5077
                        }
308✔
5078

5079
                        #endregion Read the boundary path data
5080

5081
                        //style BS 75 style of hatch 0==odd parity, 1==outermost, 2==whole area
5082
                        hatch.Style = (HatchStyleType)this._objectReader.ReadBitShort();
308✔
5083
                        //patterntype BS 76 pattern type 0==user-defined, 1==predefined, 2==custom
5084
                        hatch.PatternType = (HatchPatternType)this._objectReader.ReadBitShort();
308✔
5085

5086
                        if (!hatch.IsSolid)
308✔
5087
                        {
154✔
5088
                                //angle BD 52 hatch angle
5089
                                hatch.PatternAngle = this._objectReader.ReadBitDouble();
154✔
5090
                                //scaleorspacing BD 41 scale or spacing(pattern fill only)
5091
                                hatch.PatternScale = this._objectReader.ReadBitDouble();
154✔
5092
                                //doublehatch B 77 1 for double hatch
5093
                                hatch.IsDouble = this._objectReader.ReadBit();
154✔
5094

5095
                                //numdeflines BS 78 number of definition lines
5096
                                int numdeflines = this._objectReader.ReadBitShort();
154✔
5097
                                for (int li = 0; li < numdeflines; ++li)
2,618✔
5098
                                {
1,155✔
5099
                                        HatchPattern.Line line = new HatchPattern.Line();
1,155✔
5100
                                        //angle BD 53 line angle
5101
                                        line.Angle = this._objectReader.ReadBitDouble();
1,155✔
5102
                                        //pt0 2BD 43 / 44 pattern through this point(X, Y)
5103
                                        line.BasePoint = this._objectReader.Read2BitDouble();
1,155✔
5104
                                        //offset 2BD 45 / 56 pattern line offset
5105
                                        line.Offset = this._objectReader.Read2BitDouble();
1,155✔
5106

5107
                                        //  numdashes BS 79 number of dash length items
5108
                                        int ndashes = this._objectReader.ReadBitShort();
1,155✔
5109
                                        for (int ds = 0; ds < ndashes; ++ds)
6,622✔
5110
                                        {
2,156✔
5111
                                                //dashlength BD 49 dash length
5112
                                                line.DashLengths.Add(this._objectReader.ReadBitDouble());
2,156✔
5113
                                        }
2,156✔
5114

5115
                                        hatch.Pattern.Lines.Add(line);
1,155✔
5116
                                }
1,155✔
5117
                        }
154✔
5118

5119
                        if (hasDerivedBoundary)
308!
5120
                                //pixelsize BD 47 pixel size
5121
                                hatch.PixelSize = this._objectReader.ReadBitDouble();
×
5122

5123
                        //numseedpoints BL 98 number of seed points
5124
                        int numseedpoints = this._objectReader.ReadBitLong();
308✔
5125
                        for (int sp = 0; sp < numseedpoints; ++sp)
1,232✔
5126
                        {
308✔
5127
                                //pt0 2RD 10 seed point
5128
                                XY spt = this._objectReader.Read2RawDouble();
308✔
5129
                                hatch.SeedPoints.Add(spt);
308✔
5130
                        }
308✔
5131

5132
                        return template;
308✔
5133
                }
308✔
5134

5135
                private CadTemplate readSortentsTable()
5136
                {
154✔
5137
                        SortEntitiesTable sortTable = new SortEntitiesTable();
154✔
5138
                        CadSortensTableTemplate template = new CadSortensTableTemplate(sortTable);
154✔
5139

5140
                        this.readCommonNonEntityData(template);
154✔
5141

5142
                        //parenthandle (soft pointer)
5143
                        template.BlockOwnerHandle = this.handleReference();
154✔
5144

5145
                        //Common:
5146
                        //Numentries BL number of entries
5147
                        int numentries = this._mergedReaders.ReadBitLong();
154✔
5148
                        //Sorthandle H
5149
                        for (int i = 0; i < numentries; i++)
1,540✔
5150
                        {
616✔
5151
                                //Sort handle(numentries of these, CODE 0, i.e.part of the main bit stream, not of the handle bit stream!).
5152
                                //The sort handle does not have to point to an entity (but it can).
5153
                                //This is just the handle used for determining the drawing order of the entity specified by the entity handle in the handle bit stream.
5154
                                //When the sortentstable doesn’t have a
5155
                                //mapping from entity handle to sort handle, then the entity’s own handle is used for sorting.
5156
                                ulong sortHandle = this._objectReader.HandleReference();
616✔
5157
                                ulong entityHandle = this.handleReference();
616✔
5158

5159
                                template.Values.Add((sortHandle, entityHandle));
616✔
5160
                        }
616✔
5161

5162
                        return template;
154✔
5163
                }
154✔
5164

5165
                private CadTemplate readVisualStyle()
5166
                {
×
5167
                        VisualStyle visualStyle = new VisualStyle();
×
5168
                        CadTemplate<VisualStyle> template = new CadTemplate<VisualStyle>(visualStyle);
×
5169

5170
                        this.readCommonNonEntityData(template);
×
5171

5172
                        //WARNING: this object is not documented, the fields have been found using exploration methods and matching them with the dxf file
5173

5174
                        visualStyle.Description = this._textReader.ReadVariableText();
×
5175
                        visualStyle.Type = this._objectReader.ReadBitLong();
×
5176

5177
#if TEST
5178
                        var objValues = DwgStreamReaderBase.Explore(_objectReader);
5179
                        var textValues = DwgStreamReaderBase.Explore(_textReader);
5180
#endif
5181

5182
                        return null;
×
5183
                }
×
5184

5185
                private CadTemplate readCadImage(CadImageBase image)
5186
                {
154✔
5187
                        CadImageTemplate template = new CadImageTemplate(image);
154✔
5188

5189
                        this.readCommonEntityData(template);
154✔
5190

5191
                        image.ClassVersion = this._objectReader.ReadBitLong();
154✔
5192

5193
                        image.InsertPoint = this._objectReader.Read3BitDouble();
154✔
5194
                        image.UVector = this._objectReader.Read3BitDouble();
154✔
5195
                        image.VVector = this._objectReader.Read3BitDouble();
154✔
5196

5197
                        image.Size = this._objectReader.Read2RawDouble();
154✔
5198

5199
                        image.Flags = (ImageDisplayFlags)this._objectReader.ReadBitShort();
154✔
5200
                        image.ClippingState = this._objectReader.ReadBit();
154✔
5201
                        image.Brightness = this._objectReader.ReadByte();
154✔
5202
                        image.Contrast = this._objectReader.ReadByte();
154✔
5203
                        image.Fade = this._objectReader.ReadByte();
154✔
5204

5205
                        if (this.R2010Plus)
154✔
5206
                        {
66✔
5207
                                image.ClipMode = this._objectReader.ReadBit() ? ClipMode.Inside : ClipMode.Outside;
66!
5208
                        }
66✔
5209

5210
                        image.ClipType = (ClipType)this._objectReader.ReadBitShort();
154✔
5211
                        switch (image.ClipType)
154✔
5212
                        {
5213
                                case ClipType.Rectangular:
5214
                                        image.ClipBoundaryVertices.Add(this._objectReader.Read2RawDouble());
77✔
5215
                                        image.ClipBoundaryVertices.Add(this._objectReader.Read2RawDouble());
77✔
5216
                                        break;
77✔
5217
                                case ClipType.Polygonal:
5218
                                        int nvertices = this._objectReader.ReadBitLong();
77✔
5219
                                        for (int i = 0; i < nvertices; i++)
770✔
5220
                                        {
308✔
5221
                                                image.ClipBoundaryVertices.Add(this._objectReader.Read2RawDouble());
308✔
5222
                                        }
308✔
5223
                                        break;
77✔
5224
                        }
5225

5226
                        template.ImgDefHandle = this.handleReference();
154✔
5227
                        template.ImgReactorHandle = this.handleReference();
154✔
5228

5229
                        return template;
154✔
5230
                }
154✔
5231

5232
                private CadTemplate readImageDefinition()
5233
                {
77✔
5234
                        ImageDefinition definition = new ImageDefinition();
77✔
5235
                        CadNonGraphicalObjectTemplate template = new CadNonGraphicalObjectTemplate(definition);
77✔
5236

5237
                        this.readCommonNonEntityData(template);
77✔
5238

5239
                        //Common:
5240
                        //Clsver BL 0 class version
5241
                        definition.ClassVersion = this._mergedReaders.ReadBitLong();
77✔
5242
                        //Imgsize 2RD 10 size of image in pixels
5243
                        definition.Size = this._mergedReaders.Read2RawDouble();
77✔
5244
                        //Filepath TV 1 path to file
5245
                        definition.FileName = this._mergedReaders.ReadVariableText();
77✔
5246
                        //Isloaded B 280 0==no, 1==yes
5247
                        definition.IsLoaded = this._mergedReaders.ReadBit();
77✔
5248
                        //Resunits RC 281 0==none, 2==centimeters, 5==inches
5249
                        definition.Units = (ResolutionUnit)this._mergedReaders.ReadByte();
77✔
5250
                        //Pixelsize 2RD 11 size of one pixel in AutoCAD units
5251
                        definition.DefaultSize = this._mergedReaders.Read2RawDouble();
77✔
5252

5253
                        return template;
77✔
5254
                }
77✔
5255

5256
                private CadTemplate readImageDefinitionReactor()
5257
                {
77✔
5258
                        ImageDefinitionReactor definition = new ImageDefinitionReactor();
77✔
5259
                        CadNonGraphicalObjectTemplate template = new CadNonGraphicalObjectTemplate(definition);
77✔
5260

5261
                        this.readCommonNonEntityData(template);
77✔
5262

5263
                        //Common:
5264
                        //Classver BL 90 class version
5265
                        definition.ClassVersion = this._objectReader.ReadBitLong();
77✔
5266

5267
                        return template;
77✔
5268
                }
77✔
5269

5270
                private CadTemplate readXRecord()
5271
                {
6,037✔
5272
                        XRecord xRecord = new XRecord();
6,037✔
5273
                        CadXRecordTemplate template = new CadXRecordTemplate(xRecord);
6,037✔
5274

5275
                        this.readCommonNonEntityData(template);
6,037✔
5276

5277
                        //Common:
5278
                        //Numdatabytes BL number of databytes
5279
                        long offset = this._objectReader.ReadBitLong() + this._objectReader.Position;
6,037✔
5280

5281
                        //Databytes X databytes, however many there are to the handles
5282
                        while (this._objectReader.Position < offset)
403,159✔
5283
                        {
397,122✔
5284
                                //Common:
5285
                                //XRECORD data is pairs of:
5286
                                //RS indicator number, then data. The indicator number indicates the DXF number of the data,
5287
                                //then the data follows, so for instance an indicator of 1 would be followed by the string length (RC),
5288
                                //the dwgcodepage (RC), and then the string, for R13-R2004 files. For R2007+,
5289
                                //a string contains a short length N, and then N Unicode characters (2 bytes each).
5290
                                //An indicator of 70 would mean a 2 byte short following. An indicator of 10 indicates
5291
                                //3 8-byte doubles following. An indicator of 40 means 1 8-byte double. These indicator
5292
                                //numbers all follow the normal DXF convention for group codes.
5293
                                var code = this._objectReader.ReadShort();
397,122✔
5294
                                var groupCode = GroupCodeValue.TransformValue(code);
397,122✔
5295

5296
                                switch (groupCode)
397,122!
5297
                                {
5298
                                        case GroupCodeValueType.String:
5299
                                        case GroupCodeValueType.ExtendedDataString:
5300
                                                xRecord.CreateEntry(code, this._objectReader.ReadTextUnicode());
173,606✔
5301
                                                break;
173,606✔
5302
                                        case GroupCodeValueType.Point3D:
5303
                                                xRecord.CreateEntry(code,
620✔
5304
                                                        new XYZ(
620✔
5305
                                                                this._objectReader.ReadDouble(),
620✔
5306
                                                                this._objectReader.ReadDouble(),
620✔
5307
                                                                this._objectReader.ReadDouble()
620✔
5308
                                                                ));
620✔
5309
                                                break;
620✔
5310
                                        case GroupCodeValueType.Double:
5311
                                        case GroupCodeValueType.ExtendedDataDouble:
5312
                                                xRecord.CreateEntry(code, this._objectReader.ReadDouble());
9,960✔
5313
                                                break;
9,960✔
5314
                                        case GroupCodeValueType.Byte:
5315
                                                xRecord.CreateEntry(code, this._objectReader.ReadByte());
18,381✔
5316
                                                break;
18,381✔
5317
                                        case GroupCodeValueType.Int16:
5318
                                        case GroupCodeValueType.ExtendedDataInt16:
5319
                                                xRecord.CreateEntry(code, this._objectReader.ReadShort());
119,999✔
5320
                                                break;
119,999✔
5321
                                        case GroupCodeValueType.Int32:
5322
                                        case GroupCodeValueType.ExtendedDataInt32:
5323
                                                xRecord.CreateEntry(code, this._objectReader.ReadRawLong());
26,611✔
5324
                                                break;
26,611✔
5325
                                        case GroupCodeValueType.Int64:
NEW
5326
                                                xRecord.CreateEntry(code, this._objectReader.ReadRawULong());
×
5327
                                                break;
×
5328
                                        case GroupCodeValueType.Handle:
NEW
5329
                                                xRecord.CreateEntry(code, this._objectReader.ReadTextUnicode());
×
5330
                                                break;
×
5331
                                        case GroupCodeValueType.Bool:
5332
                                                xRecord.CreateEntry(code, this._objectReader.ReadByte() > 0);
367✔
5333
                                                break;
367✔
5334
                                        case GroupCodeValueType.Chunk:
5335
                                        case GroupCodeValueType.ExtendedDataChunk:
5336
                                                xRecord.CreateEntry(code, this._objectReader.ReadBytes(this._objectReader.ReadByte()));
42,879✔
5337
                                                break;
42,879✔
5338
                                        case GroupCodeValueType.ObjectId:
5339
                                        case GroupCodeValueType.ExtendedDataHandle:
5340
                                                xRecord.CreateEntry(code, this._objectReader.ReadRawULong());
4,699✔
5341
                                                break;
4,699✔
5342
                                        default:
NEW
5343
                                                this.notify($"Unidentified GroupCodeValueType {code} for XRecord [{xRecord.Handle}]", NotificationType.Warning);
×
5344
                                                break;
×
5345
                                }
5346
                        }
397,122✔
5347

5348
                        //R2000+:
5349
                        if (this.R2000Plus)
6,037✔
5350
                        {
3,922✔
5351
                                //Cloning flag BS 280
5352
                                xRecord.CloningFlags = (DictionaryCloningFlags)this._objectReader.ReadBitShort();
3,922✔
5353
                        }
3,922✔
5354

5355
                        long size = this._objectInitialPos + (long)(this._size * 8U) - 7L;
6,037✔
5356
                        while (this._handlesReader.PositionInBits() < size)
6,037!
5357
                        {
×
5358
                                //Handle refs H parenthandle (soft pointer)
5359
                                //[Reactors(soft pointer)]
5360
                                //xdictionary(hard owner)
5361
                                //objid object handles, as many as you can read until you run out of data
5362
                                this.handleReference();
×
5363
                        }
×
5364

5365
                        return template;
6,037✔
5366
                }
6,037✔
5367

5368
                private CadTemplate readMesh()
5369
                {
154✔
5370
                        Mesh mesh = new Mesh();
154✔
5371
                        CadMeshTemplate template = new CadMeshTemplate(mesh);
154✔
5372

5373
                        this.readCommonEntityData(template);
154✔
5374

5375
                        //Same order as dxf?
5376

5377
                        //71 BS Version
5378
                        mesh.Version = this._objectReader.ReadBitShort();
154✔
5379
                        //72 BS BlendCrease
5380
                        mesh.BlendCrease = this._objectReader.ReadBit();
154✔
5381
                        //91 BL SubdivisionLevel
5382
                        mesh.SubdivisionLevel = this._objectReader.ReadBitLong();
154✔
5383

5384
                        //92 BL nvertices
5385
                        int nvertices = this._objectReader.ReadBitLong();
154✔
5386
                        for (int i = 0; i < nvertices; i++)
19,712✔
5387
                        {
9,702✔
5388
                                //10 3BD vertice
5389
                                XYZ v = this._objectReader.Read3BitDouble();
9,702✔
5390
                                mesh.Vertices.Add(v);
9,702✔
5391
                        }
9,702✔
5392

5393
                        //Faces
5394
                        int nfaces = this._objectReader.ReadBitLong();
154✔
5395
                        for (int i = 0; i < nfaces; i++)
21,252✔
5396
                        {
10,472✔
5397
                                int faceSize = _objectReader.ReadBitLong();
10,472✔
5398
                                int[] arr = new int[faceSize];
10,472✔
5399
                                for (int j = 0; j < faceSize; j++)
101,024✔
5400
                                {
40,040✔
5401
                                        arr[j] = _objectReader.ReadBitLong();
40,040✔
5402
                                }
40,040✔
5403

5404
                                i += faceSize;
10,472✔
5405

5406
                                mesh.Faces.Add(arr.ToArray());
10,472✔
5407
                        }
10,472✔
5408

5409
                        //Edges
5410
                        int nedges = _objectReader.ReadBitLong();
154✔
5411
                        for (int k = 0; k < nedges; k++)
40,348✔
5412
                        {
20,020✔
5413
                                int start = _objectReader.ReadBitLong();
20,020✔
5414
                                int end = _objectReader.ReadBitLong();
20,020✔
5415
                                mesh.Edges.Add(new Mesh.Edge(start, end));
20,020✔
5416
                        }
20,020✔
5417

5418
                        //Crease
5419
                        int ncrease = _objectReader.ReadBitLong();
154✔
5420
                        for (int l = 0; l < ncrease; l++)
40,348✔
5421
                        {
20,020✔
5422
                                Mesh.Edge edge = mesh.Edges[l];
20,020✔
5423
                                edge.Crease = _objectReader.ReadBitDouble();
20,020✔
5424
                                mesh.Edges[l] = edge;
20,020✔
5425
                        }
20,020✔
5426

5427
                        return template;
154✔
5428
                }
154✔
5429

5430
                private CadTemplate readPlaceHolder()
5431
                {
86✔
5432
                        CadTemplate<AcdbPlaceHolder> template = new CadTemplate<AcdbPlaceHolder>(new AcdbPlaceHolder());
86✔
5433

5434
                        this.readCommonNonEntityData(template);
86✔
5435

5436
                        return template;
86✔
5437
                }
86✔
5438

5439
                private CadTemplate readPdfDefinition()
5440
                {
×
5441
                        PdfUnderlayDefinition definition = new PdfUnderlayDefinition();
×
5442
                        CadNonGraphicalObjectTemplate template = new CadNonGraphicalObjectTemplate(definition);
×
5443

5444
                        this.readCommonNonEntityData(template);
×
5445

5446
                        definition.File = this._objectReader.ReadVariableText();
×
5447
                        definition.Page = this._objectReader.ReadVariableText();
×
5448

5449
                        return template;
×
5450
                }
×
5451

5452
                private CadTemplate readPdfUnderlay()
5453
                {
×
5454
                        PdfUnderlay underlay = new PdfUnderlay();
×
5455
                        CadPdfUnderlayTemplate template = new(underlay);
×
5456

5457
                        this.readCommonEntityData(template);
×
5458

5459
                        underlay.Normal = this._objectReader.Read3BitDouble();
×
5460

5461
                        underlay.InsertPoint = this._objectReader.Read3BitDouble();
×
5462

5463
                        underlay.Rotation = this._objectReader.ReadBitDouble();
×
5464

5465
                        underlay.XScale = this._objectReader.ReadBitDouble();
×
5466
                        underlay.YScale = this._objectReader.ReadBitDouble();
×
5467
                        underlay.ZScale = this._objectReader.ReadBitDouble();
×
5468

5469
                        underlay.Flags = (UnderlayDisplayFlags)this._objectReader.ReadByte();
×
5470

5471
                        underlay.Contrast = this._objectReader.ReadByte();
×
5472
                        underlay.Fade = this._objectReader.ReadByte();
×
5473

5474
                        template.DefinitionHandle = this.handleReference();
×
5475

5476
                        return template;
×
5477
                }
×
5478

5479
                private CadTemplate readScale()
5480
                {
2,946✔
5481
                        Scale scale = new Scale();
2,946✔
5482
                        CadTemplate<Scale> template = new CadTemplate<Scale>(scale);
2,946✔
5483

5484
                        this.readCommonNonEntityData(template);
2,946✔
5485

5486
                        //BS        70        Unknown(ODA writes 0).
5487
                        this._mergedReaders.ReadBitShort();
2,946✔
5488
                        //TV        300        Name
5489
                        scale.Name = this._mergedReaders.ReadVariableText();
2,946✔
5490
                        //BD        140        Paper units(numerator)
5491
                        scale.PaperUnits = this._mergedReaders.ReadBitDouble();
2,946✔
5492
                        //BD        141        Drawing units(denominator, divided by 10).
5493
                        scale.DrawingUnits = this._mergedReaders.ReadBitDouble();
2,946✔
5494
                        //B        290        Has unit scale
5495
                        scale.IsUnitScale = this._mergedReaders.ReadBit();
2,946✔
5496

5497
                        return template;
2,946✔
5498
                }
2,946✔
5499

5500
                private CadTemplate readLayout()
5501
                {
391✔
5502
                        Layout layout = new Layout();
391✔
5503
                        CadLayoutTemplate template = new CadLayoutTemplate(layout);
391✔
5504

5505
                        this.readCommonNonEntityData(template);
391✔
5506

5507
                        this.readPlotSettings(layout);
391✔
5508

5509
                        //Common:
5510
                        //Layout name TV 1 layout name
5511
                        layout.Name = this._textReader.ReadVariableText();
391✔
5512
                        //Tab order BL 71 layout tab order
5513
                        layout.TabOrder = this._objectReader.ReadBitLong();
391✔
5514
                        //Flag BS 70 layout flags
5515
                        layout.LayoutFlags = (LayoutFlags)this._objectReader.ReadBitShort();
391✔
5516
                        //Ucs origin 3BD 13 layout ucs origin
5517
                        layout.Origin = this._objectReader.Read3BitDouble();
391✔
5518
                        //Limmin 2RD 10 layout minimum limits
5519
                        layout.MinLimits = this._objectReader.Read2RawDouble();
391✔
5520
                        //Limmax 2RD 11 layout maximum limits
5521
                        layout.MaxLimits = this._objectReader.Read2RawDouble();
391✔
5522
                        //Inspoint 3BD 12 layout insertion base point
5523
                        layout.InsertionBasePoint = this._objectReader.Read3BitDouble();
391✔
5524
                        //Ucs x axis 3BD 16 layout ucs x axis direction
5525
                        layout.XAxis = this._objectReader.Read3BitDouble();
391✔
5526
                        //Ucs y axis 3BD 17 layout ucs y axis direction
5527
                        layout.YAxis = this._objectReader.Read3BitDouble();
391✔
5528
                        //Elevation BD 146 layout elevation
5529
                        layout.Elevation = this._objectReader.ReadBitDouble();
391✔
5530
                        //Orthoview type BS 76 layout orthographic view type of UCS
5531
                        layout.UcsOrthographicType = (OrthographicType)this._objectReader.ReadBitShort();
391✔
5532
                        //Extmin 3BD 14 layout extent min
5533
                        layout.MinExtents = this._objectReader.Read3BitDouble();
391✔
5534
                        //Extmax 3BD 15 layout extent max
5535
                        layout.MaxExtents = this._objectReader.Read3BitDouble();
391✔
5536

5537
                        int nLayouts = 0;
391✔
5538
                        //R2004 +:
5539
                        if (this.R2004Plus)
391✔
5540
                                //Viewport count RL # of viewports in this layout
5541
                                nLayouts = this._objectReader.ReadBitLong();
280✔
5542

5543
                        //Common:
5544
                        //330 associated paperspace block record handle(soft pointer)
5545
                        template.PaperSpaceBlockHandle = this.handleReference();
391✔
5546
                        //331 last active viewport handle(soft pointer)
5547
                        template.ActiveViewportHandle = this.handleReference();
391✔
5548
                        //346 base ucs handle(hard pointer)
5549
                        template.BaseUcsHandle = this.handleReference();
391✔
5550
                        //345 named ucs handle(hard pointer)
5551
                        template.NamesUcsHandle = this.handleReference();
391✔
5552

5553
                        //R2004+:
5554
                        if (this.R2004Plus)
391✔
5555
                        {
280✔
5556
                                //Viewport handle(repeats Viewport count times) (soft pointer)
5557
                                for (int i = 0; i < nLayouts; ++i)
780✔
5558
                                        template.ViewportHandles.Add(this.handleReference());
110✔
5559
                        }
280✔
5560

5561
                        return template;
391✔
5562
                }
391✔
5563

5564
                private void readPlotSettings(PlotSettings plot)
5565
                {
391✔
5566
                        //Common:
5567
                        //Page setup name TV 1 plotsettings page setup name
5568
                        plot.PageName = this._textReader.ReadVariableText();
391✔
5569
                        //Printer / Config TV 2 plotsettings printer or configuration file
5570
                        plot.SystemPrinterName = this._textReader.ReadVariableText();
391✔
5571
                        //Plot layout flags BS 70 plotsettings plot layout flag
5572
                        plot.Flags = (PlotFlags)this._objectReader.ReadBitShort();
391✔
5573

5574
                        PaperMargin margin = new PaperMargin()
391✔
5575
                        {
391✔
5576
                                //Left Margin BD 40 plotsettings left margin in millimeters
391✔
5577
                                Left = this._objectReader.ReadBitDouble(),
391✔
5578
                                //Bottom Margin BD 41 plotsettings bottom margin in millimeters
391✔
5579
                                Bottom = this._objectReader.ReadBitDouble(),
391✔
5580
                                //Right Margin BD 42 plotsettings right margin in millimeters
391✔
5581
                                Right = this._objectReader.ReadBitDouble(),
391✔
5582
                                //Top Margin BD 43 plotsettings top margin in millimeters
391✔
5583
                                Top = this._objectReader.ReadBitDouble()
391✔
5584
                        };
391✔
5585
                        plot.UnprintableMargin = margin;
391✔
5586

5587
                        //Paper Width BD 44 plotsettings paper width in millimeters
5588
                        plot.PaperWidth = this._objectReader.ReadBitDouble();
391✔
5589
                        //Paper Height BD 45 plotsettings paper height in millimeters
5590
                        plot.PaperHeight = this._objectReader.ReadBitDouble();
391✔
5591

5592
                        //Paper Size TV 4 plotsettings paper size
5593
                        plot.PaperSize = this._textReader.ReadVariableText();
391✔
5594

5595
                        //Plot origin 2BD 46,47 plotsettings origin offset in millimeters
5596
                        plot.PlotOriginX = this._objectReader.ReadBitDouble();
391✔
5597
                        plot.PlotOriginY = this._objectReader.ReadBitDouble();
391✔
5598

5599
                        //Paper units BS 72 plotsettings plot paper units
5600
                        plot.PaperUnits = (PlotPaperUnits)this._objectReader.ReadBitShort();
391✔
5601
                        //Plot rotation BS 73 plotsettings plot rotation
5602
                        plot.PaperRotation = (PlotRotation)this._objectReader.ReadBitShort();
391✔
5603
                        //Plot type BS 74 plotsettings plot type
5604
                        plot.PlotType = (PlotType)this._objectReader.ReadBitShort();
391✔
5605

5606
                        //Window min 2BD 48,49 plotsettings plot window area lower left
5607
                        plot.WindowLowerLeftX = this._objectReader.ReadBitDouble();
391✔
5608
                        plot.WindowLowerLeftY = this._objectReader.ReadBitDouble();
391✔
5609
                        //Window max 2BD 140,141 plotsettings plot window area upper right
5610
                        plot.WindowUpperLeftX = this._objectReader.ReadBitDouble();
391✔
5611
                        plot.WindowUpperLeftY = this._objectReader.ReadBitDouble();
391✔
5612

5613
                        //R13 - R2000 Only:
5614
                        if (this._version >= ACadVersion.AC1012 && this._version <= ACadVersion.AC1015)
391!
5615
                                //Plot view name T 6 plotsettings plot view name
5616
                                plot.PlotViewName = this._textReader.ReadVariableText();
111✔
5617

5618
                        //Common:
5619
                        //Real world units BD 142 plotsettings numerator of custom print scale
5620
                        plot.NumeratorScale = this._objectReader.ReadBitDouble();
391✔
5621
                        //Drawing units BD 143 plotsettings denominator of custom print scale
5622
                        plot.DenominatorScale = this._objectReader.ReadBitDouble();
391✔
5623
                        //Current style sheet TV 7 plotsettings current style sheet
5624
                        plot.StyleSheet = this._textReader.ReadVariableText();
391✔
5625
                        //Scale type BS 75 plotsettings standard scale type
5626
                        plot.ScaledFit = (ScaledType)this._objectReader.ReadBitShort();
391✔
5627
                        //Scale factor BD 147 plotsettings scale factor
5628
                        plot.StandardScale = this._objectReader.ReadBitDouble();
391✔
5629
                        //Paper image origin 2BD 148,149 plotsettings paper image origin
5630
                        plot.PaperImageOrigin = this._objectReader.Read2BitDouble();
391✔
5631

5632
                        //R2004+:
5633
                        if (this.R2004Plus)
391✔
5634
                        {
280✔
5635
                                //Shade plot mode BS 76
5636
                                plot.ShadePlotMode = (ShadePlotMode)this._objectReader.ReadBitShort();
280✔
5637
                                //Shade plot res.Level BS 77
5638
                                plot.ShadePlotResolutionMode = (ShadePlotResolutionMode)this._objectReader.ReadBitShort();
280✔
5639
                                //Shade plot custom DPI BS 78
5640
                                plot.ShadePlotDPI = this._objectReader.ReadBitShort();
280✔
5641

5642
                                //6 plot view handle(hard pointer)
5643
                                ulong plotViewHandle = this.handleReference();
280✔
5644
                        }
280✔
5645

5646
                        //R2007 +:
5647
                        if (this.R2007Plus)
391✔
5648
                                //Visual Style handle(soft pointer)
5649
                                this.handleReference();
225✔
5650
                }
391✔
5651

5652
                #endregion Object readers
5653

5654
                private CadTemplate readDwgColor()
5655
                {
×
5656
                        return null;
×
5657

5658
                        DwgColorTemplate.DwgColor dwgColor = new DwgColorTemplate.DwgColor();
5659
                        DwgColorTemplate template = new DwgColorTemplate(dwgColor);
5660

5661
                        this.readCommonNonEntityData(template);
5662

5663
                        short colorIndex = this._objectReader.ReadBitShort();
5664

5665
                        if (this.R2004Plus && this._version < ACadVersion.AC1032)
5666
                        {
5667
                                short index = (short)this._objectReader.ReadBitLong();
5668
                                byte flags = this._objectReader.ReadByte();
5669

5670
                                if ((flags & 1U) > 0U)
5671
                                        template.Name = this._textReader.ReadVariableText();
5672

5673
                                if ((flags & 2U) > 0U)
5674
                                        template.BookName = this._textReader.ReadVariableText();
5675

5676
                                dwgColor.Color = new Color(index);
5677
                        }
5678

5679
                        dwgColor.Color = new Color(colorIndex);
5680

5681
                        return null;
5682
                }
×
5683
        }
5684
}
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