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

DomCR / ACadSharp / 12351527569

16 Dec 2024 11:18AM UTC coverage: 75.448% (+0.01%) from 75.438%
12351527569

push

github

web-flow
Merge pull request #510 from DomCR/dict-w-default-fix

Dictionary with def & blocks

5131 of 7505 branches covered (68.37%)

Branch coverage included in aggregate %.

13 of 23 new or added lines in 3 files covered. (56.52%)

2 existing lines in 1 file now uncovered.

20412 of 26350 relevant lines covered (77.46%)

36631.49 hits per line

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

80.59
/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs
1
using ACadSharp.Blocks;
2
using ACadSharp.Entities;
3
using ACadSharp.Objects;
4
using ACadSharp.Tables;
5
using ACadSharp.Tables.Collections;
6
using CSUtilities.Converters;
7
using CSUtilities.Text;
8
using System;
9
using System.Collections.Generic;
10
using System.IO;
11
using System.Linq;
12
using System.Text;
13

14
namespace ACadSharp.IO.DWG
15
{
16
        internal partial class DwgObjectWriter : DwgSectionIO
17
        {
18
                public override string SectionName => DwgSectionDefinition.AcDbObjects;
×
19

20
                /// <summary>
21
                /// Key : handle | Value : Offset
22
                /// </summary>
23
                public Dictionary<ulong, long> Map { get; } = new Dictionary<ulong, long>();
2,444✔
24

25
                public bool WriteXRecords { get; }
×
26

27
                private Dictionary<ulong, CadDictionary> _dictionaries = new();
38✔
28

29
                private Queue<CadObject> _objects = new();
38✔
30

31
                private MemoryStream _msmain;
32

33
                private IDwgStreamWriter _writer;
34

35
                private Stream _stream;
36

37
                private CadDocument _document;
38

39
                private Entity _prev;
40

41
                private Entity _next;
42

43
                public DwgObjectWriter(Stream stream, CadDocument document, Encoding encoding, bool writeXRecords = true) : base(document.Header.Version)
38✔
44
                {
38✔
45
                        this._stream = stream;
38✔
46
                        this._document = document;
38✔
47

48
                        this._msmain = new MemoryStream();
38✔
49
                        this._writer = DwgStreamWriterBase.GetMergedWriter(document.Header.Version, this._msmain, encoding);
38✔
50
                        this.WriteXRecords = writeXRecords;
38✔
51
                }
38✔
52

53
                public void Write()
54
                {
38✔
55
                        //For R18 and later the section data (right after the page header) starts with a
56
                        //RL value of 0x0dca (meaning unknown).
57
                        if (this.R2004Plus)
38✔
58
                        {
26✔
59
                                byte[] arr = LittleEndianConverter.Instance.GetBytes((int)0xDCA);
26✔
60
                                this._stream.Write(arr, 0, arr.Length);
26✔
61
                        }
26✔
62

63
                        this._objects.Enqueue(this._document.RootDictionary);
38✔
64

65
                        this.writeBlockControl();
38✔
66
                        this.writeTable(this._document.Layers);
38✔
67
                        this.writeTable(this._document.TextStyles);
38✔
68
                        this.writeLTypeControlObject();
38✔
69
                        this.writeTable(this._document.Views);
38✔
70
                        this.writeTable(this._document.UCSs);
38✔
71
                        this.writeTable(this._document.VPorts);
38✔
72
                        this.writeTable(this._document.AppIds);
38✔
73
                        //For some reason the dimension must be writen the last
74
                        this.writeTable(this._document.DimensionStyles);
38✔
75

76
                        this.writeBlockEntities();
38✔
77
                        this.writeObjects();
38✔
78
                }
38✔
79

80
                private void writeLTypeControlObject()
81
                {
38✔
82
                        this.writeCommonNonEntityData(this._document.LineTypes);
38✔
83

84
                        //Common:
85
                        //Numentries BL 70
86
                        this._writer.WriteBitLong(this._document.LineTypes.Count - 2);
38✔
87

88
                        foreach (LineType item in this._document.LineTypes)
342✔
89
                        {
114✔
90
                                if (item.Name.Equals(LineType.ByBlockName, StringComparison.OrdinalIgnoreCase)
114✔
91
                                        || item.Name.Equals(LineType.ByLayerName, StringComparison.OrdinalIgnoreCase))
114✔
92
                                {
76✔
93
                                        continue;
76✔
94
                                }
95

96
                                //numentries handles in the file (soft owner)
97
                                this._writer.HandleReference(DwgReferenceType.SoftOwnership, item);
38✔
98
                        }
38✔
99

100
                        //the linetypes, ending with BYLAYER and BYBLOCK.
101
                        this._writer.HandleReference(DwgReferenceType.HardOwnership, this._document.LineTypes.ByBlock);
38✔
102
                        this._writer.HandleReference(DwgReferenceType.HardOwnership, this._document.LineTypes.ByLayer);
38✔
103

104
                        this.registerObject(this._document.LineTypes);
38✔
105

106
                        this.writeEntries(this._document.LineTypes);
38✔
107
                }
38✔
108

109
                private void writeBlockControl()
110
                {
38✔
111
                        this.writeCommonNonEntityData(this._document.BlockRecords);
38✔
112

113
                        //Common:
114
                        //Numentries BL 70 Doesn't count *MODEL_SPACE and *PAPER_SPACE.
115
                        this._writer.WriteBitLong(this._document.BlockRecords.Count - 2);
38✔
116

117
                        foreach (var item in this._document.BlockRecords)
282✔
118
                        {
84✔
119
                                if (item.Name.Equals(BlockRecord.ModelSpaceName, StringComparison.OrdinalIgnoreCase)
84✔
120
                                        || item.Name.Equals(BlockRecord.PaperSpaceName, StringComparison.OrdinalIgnoreCase))
84✔
121
                                {
76✔
122
                                        continue;
76✔
123
                                }
124

125
                                //numentries handles of blockheaders in the file (soft owner)
126
                                this._writer.HandleReference(DwgReferenceType.SoftOwnership, item);
8✔
127
                        }
8✔
128

129
                        //*MODEL_SPACE and *PAPER_SPACE(hard owner).
130
                        this._writer.HandleReference(DwgReferenceType.HardOwnership, this._document.ModelSpace);
38✔
131
                        this._writer.HandleReference(DwgReferenceType.HardOwnership, this._document.PaperSpace);
38✔
132

133
                        this.registerObject(this._document.BlockRecords);
38✔
134

135
                        this.writeEntries(this._document.BlockRecords);
38✔
136
                }
38✔
137

138
                private void writeTable<T>(Table<T> table)
139
                        where T : TableEntry
140
                {
266✔
141
                        this.writeCommonNonEntityData(table);
266✔
142

143
                        //Common:
144
                        //Numentries BL 70
145
                        this._writer.WriteBitLong(table.Count);
266✔
146

147
                        if (this.R2000Plus && table is DimensionStylesTable)
266✔
148
                        {
31✔
149
                                //Undocumented: this byte is found only in the DimensionStylesTable
150
                                this._writer.WriteByte(0);
31✔
151
                        }
31✔
152

153
                        foreach (var item in table)
1,178✔
154
                        {
190✔
155
                                //numentries handles in the file (soft owner)
156
                                this._writer.HandleReference(DwgReferenceType.SoftOwnership, item);
190✔
157
                        }
190✔
158

159
                        this.registerObject(table);
266✔
160

161
                        this.writeEntries(table);
266✔
162
                }
266✔
163

164
                private void writeEntries<T>(Table<T> table)
165
                        where T : TableEntry
166
                {
342✔
167
                        foreach (var entry in table)
1,802✔
168
                        {
388✔
169
                                switch (entry)
388!
170
                                {
171
                                        case AppId app:
172
                                                this.writeAppId(app);
38✔
173
                                                break;
38✔
174
                                        case BlockRecord blkRecord:
175
                                                this.writeBlockRecord(blkRecord);
84✔
176
                                                break;
84✔
177
                                        case Layer layer:
178
                                                this.writeLayer(layer);
38✔
179
                                                break;
38✔
180
                                        case LineType ltype:
181
                                                this.writeLineType(ltype);
114✔
182
                                                break;
114✔
183
                                        case TextStyle tstyle:
184
                                                this.writeTextStyle(tstyle);
38✔
185
                                                break;
38✔
186
                                        case UCS ucs:
187
                                                this.writeUCS(ucs);
×
188
                                                break;
×
189
                                        case View view:
190
                                                this.writeView(view);
×
191
                                                break;
×
192
                                        case DimensionStyle dstyle:
193
                                                this.writeDimensionStyle(dstyle);
38✔
194
                                                break;
38✔
195
                                        case VPort vport:
196
                                                this.writeVPort(vport);
38✔
197
                                                break;
38✔
198
                                        default:
199
                                                this.notify($"Table entry not implemented : {entry.GetType().FullName}", NotificationType.NotImplemented);
×
200
                                                break;
×
201
                                }
202
                        }
388✔
203
                }
342✔
204

205
                private void writeBlockEntities()
206
                {
38✔
207
                        foreach (BlockRecord blkRecord in this._document.BlockRecords)
282✔
208
                        {
84✔
209
                                this.writeBlockBegin(blkRecord.BlockEntity);
84✔
210

211
                                this._prev = null;
84✔
212
                                this._next = null;
84✔
213
                                Entity[] arr = blkRecord.Entities.ToArray();
84✔
214
                                for (int i = 0; i < arr.Length; i++)
416✔
215
                                {
124✔
216
                                        this._prev = arr.ElementAtOrDefault(i - 1);
124✔
217
                                        Entity e = arr[i];
124✔
218
                                        this._next = arr.ElementAtOrDefault(i + 1);
124✔
219

220
                                        this.writeEntity(e);
124✔
221
                                }
124✔
222

223
                                this._prev = null;
84✔
224
                                this._next = null;
84✔
225

226
                                this.writeBlockEnd(blkRecord.BlockEnd);
84✔
227
                        }
84✔
228
                }
38✔
229

230
                private void writeAppId(AppId app)
231
                {
38✔
232
                        this.writeCommonNonEntityData(app);
38✔
233

234
                        //Common:
235
                        //Entry name TV 2
236
                        this._writer.WriteVariableText(app.Name);
38✔
237

238
                        this.writeXrefDependantBit(app);
38✔
239

240
                        //Unknown RC 71 Undoc'd 71-group; doesn't even appear in DXF or an entget if it's 0.
241
                        this._writer.WriteByte(0);
38✔
242

243
                        //External reference block handle(hard pointer)        ??
244
                        this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
38✔
245

246
                        this.registerObject(app);
38✔
247
                }
38✔
248

249
                private void writeBlockRecord(BlockRecord blkRecord)
250
                {
84✔
251
                        this.writeBlockHeader(blkRecord);
84✔
252
                }
84✔
253

254
                private void writeBlockHeader(BlockRecord record)
255
                {
84✔
256
                        this.writeCommonNonEntityData(record);
84✔
257

258
                        //Common:
259
                        //Entry name TV 2
260
                        if (record.Flags.HasFlag(BlockTypeFlags.Anonymous))
84!
NEW
261
                        {
×
262
                                //Warning: anonymous blocks do not write the full name, only *{type character}
NEW
263
                                this._writer.WriteVariableText(record.Name.Substring(0, 2));
×
NEW
264
                        }
×
265
                        else
266
                        {
84✔
267
                                this._writer.WriteVariableText(record.Name);
84✔
268
                        }
84✔
269

270
                        this.writeXrefDependantBit(record);
84✔
271

272
                        //Anonymous B 1 if this is an anonymous block (1 bit)
273
                        this._writer.WriteBit(record.Flags.HasFlag(BlockTypeFlags.Anonymous));
84✔
274

275
                        //Hasatts B 1 if block contains attdefs (2 bit)
276
                        this._writer.WriteBit(record.HasAttributes);
84✔
277

278
                        //Blkisxref B 1 if block is xref (4 bit)
279
                        this._writer.WriteBit(record.Flags.HasFlag(BlockTypeFlags.XRef));
84✔
280

281
                        //Xrefoverlaid B 1 if an overlaid xref (8 bit)
282
                        this._writer.WriteBit(record.Flags.HasFlag(BlockTypeFlags.XRefOverlay));
84✔
283

284
                        //R2000+:
285
                        if (this.R2000Plus)
84✔
286
                        {
68✔
287
                                //Loaded Bit B 0 indicates loaded for an xref
288
                                this._writer.WriteBit(record.Flags.HasFlag(BlockTypeFlags.XRef));
68✔
289
                        }
68✔
290

291
                        //R2004+:
292
                        if (this.R2004Plus
84✔
293
                                && !record.Flags.HasFlag(BlockTypeFlags.XRef)
84✔
294
                                && !record.Flags.HasFlag(BlockTypeFlags.XRefOverlay))
84✔
295
                        {
57✔
296
                                //Owned Object Count BL Number of objects owned by this object.
297
                                _writer.WriteBitLong(record.Entities.Count());
57✔
298
                        }
57✔
299

300
                        //Common:
301
                        //Base pt 3BD 10 Base point of block.
302
                        this._writer.Write3BitDouble(record.BlockEntity.BasePoint);
84✔
303
                        //Xref pname TV 1 Xref pathname. That's right: DXF 1 AND 3!
304
                        //3 1 appears in a tblnext/ search elist; 3 appears in an entget.
305
                        this._writer.WriteVariableText(record.BlockEntity.XrefPath);
84✔
306

307
                        //R2000+:
308
                        if (this.R2000Plus)
84✔
309
                        {
68✔
310
                                //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.
311
                                foreach (var item in this._document.Entities.OfType<Insert>()
216✔
312
                                        .Where(i => i.Block.Name == record.Name))
86✔
313
                                {
6✔
314
                                        this._writer.WriteByte(1);
6✔
315
                                }
6✔
316

317
                                this._writer.WriteByte(0);
68✔
318

319
                                //Block Description TV 4 Block description.
320
                                this._writer.WriteVariableText(record.BlockEntity.Comments);
68✔
321

322
                                //Size of preview data BL Indicates number of bytes of data following.
323
                                this._writer.WriteBitLong(0);
68✔
324
                        }
68✔
325

326
                        //R2007+:
327
                        if (this.R2007Plus)
84✔
328
                        {
44✔
329
                                //Insert units BS 70
330
                                this._writer.WriteBitShort((short)record.Units);
44✔
331
                                //Explodable B 280
332
                                this._writer.WriteBit(record.IsExplodable);
44✔
333
                                //Block scaling RC 281
334
                                this._writer.WriteByte((byte)(record.CanScale ? 1u : 0u));
44✔
335
                        }
44✔
336

337
                        //NULL(hard pointer)
338
                        this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
84✔
339
                        //BLOCK entity. (hard owner)
340
                        //Block begin object
341
                        this._writer.HandleReference(DwgReferenceType.HardOwnership, record.BlockEntity);
84✔
342

343
                        //R13-R2000:
344
                        if (this._version >= ACadVersion.AC1012 && this._version <= ACadVersion.AC1015
84✔
345
                                        && !record.Flags.HasFlag(BlockTypeFlags.XRef)
84✔
346
                                        && !record.Flags.HasFlag(BlockTypeFlags.XRefOverlay))
84✔
347
                        {
27✔
348
                                if (record.Entities.Any())
27✔
349
                                {
5✔
350
                                        //first entity in the def. (soft pointer)
351
                                        this._writer.HandleReference(DwgReferenceType.SoftPointer, record.Entities.First());
5✔
352
                                        //last entity in the def. (soft pointer)
353
                                        this._writer.HandleReference(DwgReferenceType.SoftPointer, record.Entities.Last());
5✔
354
                                }
5✔
355
                                else
356
                                {
22✔
357
                                        this._writer.HandleReference(DwgReferenceType.SoftPointer, 0);
22✔
358
                                        this._writer.HandleReference(DwgReferenceType.SoftPointer, 0);
22✔
359
                                }
22✔
360
                        }
27✔
361

362
                        //R2004+:
363
                        if (this.R2004Plus)
84✔
364
                        {
57✔
365
                                foreach (var item in record.Entities)
327✔
366
                                {
78✔
367
                                        //H[ENTITY(hard owner)] Repeats “Owned Object Count” times.
368
                                        this._writer.HandleReference(DwgReferenceType.HardOwnership, item);
78✔
369
                                }
78✔
370
                        }
57✔
371

372
                        //Common:
373
                        //ENDBLK entity. (hard owner)
374
                        this._writer.HandleReference(DwgReferenceType.HardOwnership, record.BlockEnd);
84✔
375

376
                        //R2000+:
377
                        if (this.R2000Plus)
84✔
378
                        {
68✔
379
                                foreach (var item in this._document.Entities.OfType<Insert>()
216✔
380
                                        .Where(i => i.Block.Name == record.Name))
86✔
381
                                {
6✔
382
                                        this._writer.HandleReference(DwgReferenceType.SoftPointer, item);
6✔
383
                                }
6✔
384

385
                                //Layout Handle H(hard pointer)
386
                                this._writer.HandleReference(DwgReferenceType.HardPointer, record.Layout);
68✔
387
                        }
68✔
388

389
                        this.registerObject(record);
84✔
390
                }
84✔
391

392
                private void writeBlockBegin(Block block)
393
                {
84✔
394
                        this.writeCommonEntityData(block);
84✔
395

396
                        //Common:
397
                        //Entry name TV 2
398
                        this._writer.WriteVariableText(block.Name);
84✔
399

400
                        this.registerObject(block);
84✔
401
                }
84✔
402

403
                private void writeBlockEnd(BlockEnd blkEnd)
404
                {
84✔
405
                        this.writeCommonEntityData(blkEnd);
84✔
406

407
                        this.registerObject(blkEnd);
84✔
408
                }
84✔
409

410
                private void writeLayer(Layer layer)
411
                {
38✔
412
                        this.writeCommonNonEntityData(layer);
38✔
413

414
                        //Common:
415
                        //Entry name TV 2
416
                        this._writer.WriteVariableText(layer.Name);
38✔
417

418
                        this.writeXrefDependantBit(layer);
38✔
419

420
                        //R13-R14 Only:
421
                        if (this.R13_14Only)
38✔
422
                        {
7✔
423
                                //Frozen B 70 if frozen (1 bit)
424
                                this._writer.WriteBit(layer.Flags.HasFlag(LayerFlags.Frozen));
7✔
425
                                //On B if on.
426
                                this._writer.WriteBit(layer.IsOn);
7✔
427
                                //Frz in new B 70 if frozen by default in new viewports (2 bit)
428
                                this._writer.WriteBit(layer.Flags.HasFlag(LayerFlags.FrozenNewViewports));
7✔
429
                                //Locked B 70 if locked (4 bit)
430
                                this._writer.WriteBit(layer.Flags.HasFlag(LayerFlags.Locked));
7✔
431
                        }
7✔
432

433
                        //R2000+:
434
                        if (this.R2000Plus)
38✔
435
                        {
31✔
436
                                //and lineweight (mask with 0x03E0)
437
                                short values = (short)(CadUtils.ToIndex(layer.LineWeight) << 5);
31✔
438

439
                                //contains frozen (1 bit),
440
                                if (layer.Flags.HasFlag(LayerFlags.Frozen))
31!
441
                                        values |= 0b1;
×
442

443
                                //on (2 bit)
444
                                if (!layer.IsOn)
31!
445
                                        values |= 0b10;
×
446

447
                                //frozen by default in new viewports (4 bit)
448
                                if (layer.Flags.HasFlag(LayerFlags.Frozen))
31!
449
                                        values |= 0b100;
×
450

451
                                //locked (8 bit)
452
                                if (layer.Flags.HasFlag(LayerFlags.Locked))
31!
453
                                        values |= 0b1000;
×
454

455
                                //plotting flag (16 bit),
456
                                if (layer.PlotFlag)
31✔
457
                                        values |= 0b10000;
31✔
458

459
                                //Values BS 70,290,370
460
                                this._writer.WriteBitShort(values);
31✔
461
                        }
31✔
462

463
                        //Common:
464
                        //Color CMC 62
465
                        this._writer.WriteCmColor(layer.Color);
38✔
466

467
                        //External reference block handle(hard pointer)
468
                        this._writer.HandleReference(DwgReferenceType.HardPointer, null);
38✔
469

470
                        //R2000+:
471
                        if (this.R2000Plus)
38✔
472
                        {
31✔
473
                                //H 390 Plotstyle (hard pointer), by default points to PLACEHOLDER with handle 0x0f.
474
                                this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
31✔
475
                        }
31✔
476

477
                        //R2007+:
478
                        if (this.R2007Plus)
38✔
479
                        {
20✔
480
                                //H 347 Material
481
                                this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
20✔
482
                        }
20✔
483

484
                        //Common:
485
                        //H 6 linetype (hard pointer)
486
                        this._writer.HandleReference(DwgReferenceType.HardPointer, layer.LineType.Handle);
38✔
487

488
                        if (R2013Plus)
38✔
489
                        {
12✔
490
                                //H Unknown handle (hard pointer). Always seems to be NULL.
491
                                this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
12✔
492
                        }
12✔
493

494
                        this.registerObject(layer);
38✔
495
                }
38✔
496

497
                private void writeLineType(LineType ltype)
498
                {
114✔
499
                        this.writeCommonNonEntityData(ltype);
114✔
500

501
                        //Common:
502
                        //Entry name TV 2
503
                        this._writer.WriteVariableText(ltype.Name);
114✔
504

505
                        this.writeXrefDependantBit(ltype);
114✔
506

507
                        //Description TV 3
508
                        this._writer.WriteVariableText(ltype.Description);
114✔
509
                        //Pattern Len BD 40
510
                        this._writer.WriteBitDouble(ltype.PatternLen);
114✔
511
                        //Alignment RC 72 Always 'A'.
512
                        this._writer.WriteByte((byte)ltype.Alignment);
114✔
513

514
                        //Numdashes RC 73 The number of repetitions of the 49...74 data.
515
                        this._writer.WriteByte((byte)ltype.Segments.Count());
114✔
516
                        bool isText = false;
114✔
517
                        foreach (LineType.Segment segment in ltype.Segments)
342!
518
                        {
×
519
                                //Dash length BD 49 Dash or dot specifier.
520
                                this._writer.WriteBitDouble(segment.Length);
×
521
                                //Complex shapecode BS 75 Shape number if shapeflag is 2, or index into the string area if shapeflag is 4.
522
                                this._writer.WriteBitShort(segment.ShapeNumber);
×
523

524
                                //X - offset RD 44 (0.0 for a simple dash.)
525
                                //Y - offset RD 45(0.0 for a simple dash.)
526
                                this._writer.WriteRawDouble(segment.Offset.X);
×
527
                                this._writer.WriteRawDouble(segment.Offset.Y);
×
528

529
                                //Scale BD 46 (1.0 for a simple dash.)
530
                                this._writer.WriteBitDouble(segment.Scale);
×
531
                                //Rotation BD 50 (0.0 for a simple dash.)
532
                                this._writer.WriteBitDouble(segment.Rotation);
×
533
                                //Shapeflag BS 74 bit coded:
534
                                this._writer.WriteBitShort((short)segment.Shapeflag);
×
535

536
                                if (segment.Shapeflag.HasFlag(LinetypeShapeFlags.Text))
×
537
                                        isText = true;
×
538
                        }
×
539

540
                        //R2004 and earlier:
541
                        if (this._version <= ACadVersion.AC1018)
114✔
542
                        {
54✔
543
                                //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.
544
                                //First byte is always 0 for R13 and data starts at byte 1.
545
                                //In R14 it is not a valid data start from byte 0.
546
                                //(The 9 - group is undocumented.)
547
                                for (int i = 0; i < 256; i++)
27,756✔
548
                                {
13,824✔
549
                                        //TODO: Write the line type text area
550
                                        this._writer.WriteByte(0);
13,824✔
551
                                }
13,824✔
552
                        }
54✔
553

554
                        //R2007+:
555
                        if (this.R2007Plus && isText)
114!
556
                        {
×
557
                                for (int i = 0; i < 512; i++)
×
558
                                {
×
559
                                        //TODO: Write the line type text area
560
                                        this._writer.WriteByte(0);
×
561
                                }
×
562
                        }
×
563

564
                        //Common:
565
                        //External reference block handle(hard pointer)
566
                        this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
114✔
567

568
                        foreach (var segment in ltype.Segments)
342!
569
                        {
×
570
                                //340 shapefile for dash/shape (1 each) (hard pointer)
571
                                this._writer.HandleReference(DwgReferenceType.HardPointer, segment.Style);
×
572
                        }
×
573

574
                        this.registerObject(ltype);
114✔
575
                }
114✔
576

577
                private void writeTextStyle(TextStyle style)
578
                {
38✔
579
                        this.writeCommonNonEntityData(style);
38✔
580

581
                        //Common:
582
                        //Entry name TV 2
583
                        if (style.IsShapeFile)
38!
584
                        {
×
585
                                this._writer.WriteVariableText(string.Empty);
×
586
                        }
×
587
                        else
588
                        {
38✔
589
                                this._writer.WriteVariableText(style.Name);
38✔
590
                        }
38✔
591

592
                        this.writeXrefDependantBit(style);
38✔
593

594
                        //shape file B 1 if a shape file rather than a font (1 bit)
595
                        this._writer.WriteBit(style.Flags.HasFlag(StyleFlags.IsShape));
38✔
596

597
                        //Vertical B 1 if vertical (4 bit of flag)
598
                        this._writer.WriteBit(style.Flags.HasFlag(StyleFlags.VerticalText));
38✔
599
                        //Fixed height BD 40
600
                        this._writer.WriteBitDouble(style.Height);
38✔
601
                        //Width factor BD 41
602
                        this._writer.WriteBitDouble(style.Width);
38✔
603
                        //Oblique ang BD 50
604
                        this._writer.WriteBitDouble(style.ObliqueAngle);
38✔
605
                        //Generation RC 71 Generation flags (not bit-pair coded).
606
                        this._writer.WriteByte((byte)style.MirrorFlag);
38✔
607
                        //Last height BD 42
608
                        this._writer.WriteBitDouble(style.LastHeight);
38✔
609
                        //Font name TV 3
610
                        this._writer.WriteVariableText(style.Filename);
38✔
611
                        //Bigfont name TV 4
612
                        this._writer.WriteVariableText(style.BigFontFilename);
38✔
613

614
                        this._writer.HandleReference(DwgReferenceType.HardPointer, this._document.TextStyles);
38✔
615

616
                        this.registerObject(style);
38✔
617
                }
38✔
618

619
                private void writeUCS(UCS ucs)
620
                {
×
621
                        this.writeCommonNonEntityData(ucs);
×
622

623
                        //Common:
624
                        //Entry name TV 2
625
                        this._writer.WriteVariableText(ucs.Name);
×
626

627
                        this.writeXrefDependantBit(ucs);
×
628

629
                        //Origin 3BD 10
630
                        this._writer.Write3BitDouble(ucs.Origin);
×
631
                        //X - direction 3BD 11
632
                        this._writer.Write3BitDouble(ucs.XAxis);
×
633
                        //Y - direction 3BD 12
634
                        this._writer.Write3BitDouble(ucs.YAxis);
×
635

636
                        //R2000+:
637
                        if (this.R2000Plus)
×
638
                        {
×
639
                                //Elevation BD 146
640
                                this._writer.WriteBitDouble(ucs.Elevation);
×
641
                                //OrthographicViewType BS 79        //dxf docs: 79        Always 0
642
                                this._writer.WriteBitShort((short)ucs.OrthographicViewType);
×
643
                                //OrthographicType BS 71
644
                                this._writer.WriteBitShort((short)ucs.OrthographicType);
×
645
                        }
×
646

647
                        //Common:
648
                        //Handle refs H ucs control object (soft pointer)
649
                        this._writer.HandleReference(DwgReferenceType.SoftPointer, this._document.UCSs);
×
650

651
                        //R2000 +:
652
                        if (this.R2000Plus)
×
653
                        {
×
654
                                //Base UCS Handle H 346 hard pointer
655
                                this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
×
656
                                //Named UCS Handle H -hard pointer, not present in DXF
657
                                this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
×
658
                        }
×
659

660
                        this.registerObject(ucs);
×
661
                }
×
662

663
                private void writeView(View view)
664
                {
×
665
                        this.writeCommonNonEntityData(view);
×
666

667
                        //Common:
668
                        //Entry name TV 2
669
                        this._writer.WriteVariableText(view.Name);
×
670

671
                        this.writeXrefDependantBit(view);
×
672

673
                        //View height BD 40
674
                        this._writer.WriteBitDouble(view.Height);
×
675
                        //View width BD 41
676
                        this._writer.WriteBitDouble(view.Width);
×
677
                        //View center 2RD 10(Not bit - pair coded.)
678
                        this._writer.Write2RawDouble(view.Center);
×
679
                        //Target 3BD 12
680
                        this._writer.Write3BitDouble(view.Target);
×
681
                        //View dir 3BD 11 DXF doc suggests from target toward camera.
682
                        this._writer.Write3BitDouble(view.Direction);
×
683
                        //Twist angle BD 50 Radians
684
                        this._writer.WriteBitDouble(view.Angle);
×
685
                        //Lens length BD 42
686
                        this._writer.WriteBitDouble(view.LensLength);
×
687
                        //Front clip BD 43
688
                        this._writer.WriteBitDouble(view.FrontClipping);
×
689
                        //Back clip BD 44
690
                        this._writer.WriteBitDouble(view.BackClipping);
×
691

692
                        //View mode X 71 4 bits: 0123
693
                        //Note that only bits 0, 1, 2, and 4 of the 71 can be specified -- not bit 3 (8).
694
                        //0 : 71's bit 0 (1)
695
                        this._writer.WriteBit(view.ViewMode.HasFlag(ViewModeType.PerspectiveView));
×
696
                        //1 : 71's bit 1 (2)
697
                        this._writer.WriteBit(view.ViewMode.HasFlag(ViewModeType.FrontClipping));
×
698
                        //2 : 71's bit 2 (4)
699
                        this._writer.WriteBit(view.ViewMode.HasFlag(ViewModeType.BackClipping));
×
700
                        //3 : OPPOSITE of 71's bit 4 (16)
701
                        this._writer.WriteBit(view.ViewMode.HasFlag(ViewModeType.FrontClippingZ));
×
702

703
                        //R2000+:
704
                        if (this.R2000Plus)
×
705
                        {
×
706
                                //Render Mode RC 281
707
                                this._writer.WriteByte((byte)view.RenderMode);
×
708
                        }
×
709

710
                        //R2007+:
711
                        if (this.R2007Plus)
×
712
                        {
×
713
                                //Use default lights B ? Default value is true
714
                                this._writer.WriteBit(true);
×
715
                                //Default lighting RC ? Default value is 1
716
                                this._writer.WriteByte(1);
×
717
                                //Brightness BD ? Default value is 0
718
                                this._writer.WriteBitDouble(0.0);
×
719
                                //Contrast BD ? Default value is 0
720
                                this._writer.WriteBitDouble(0.0);
×
721
                                //Abient color CMC? Default value is indexed color 250
722
                                this._writer.WriteCmColor(new Color(250));
×
723
                        }
×
724

725
                        //Common:
726
                        //Pspace flag B 70 Bit 0(1) of the 70 - group.
727
                        this._writer.WriteBit(view.Flags.HasFlag((StandardFlags)0b1));
×
728

729
                        if (this.R2000Plus)
×
730
                        {
×
731
                                this._writer.WriteBit(view.IsUcsAssociated);
×
732
                                if (view.IsUcsAssociated)
×
733
                                {
×
734
                                        //Origin 3BD 10 This and next 4 R2000 items are present only if 72 value is 1.
735
                                        this._writer.Write3BitDouble(view.UcsOrigin);
×
736
                                        //X-direction 3BD 11
737
                                        this._writer.Write3BitDouble(view.UcsXAxis);
×
738
                                        //Y-direction 3BD 12
739
                                        this._writer.Write3BitDouble(view.UcsYAxis);
×
740
                                        //Elevation BD 146
741
                                        this._writer.WriteBitDouble(view.UcsElevation);
×
742
                                        //OrthographicViewType BS 79
743
                                        this._writer.WriteBitShort((short)view.UcsOrthographicType);
×
744
                                }
×
745
                        }
×
746

747
                        //Common:
748
                        //Handle refs H view control object (soft pointer)
749
                        this._writer.HandleReference(DwgReferenceType.SoftPointer, this._document.Views);
×
750

751
                        //R2007+:
752
                        if (this.R2007Plus)
×
753
                        {
×
754
                                //Camera plottable B 73
755
                                this._writer.WriteBit(view.IsPlottable);
×
756

757
                                //Background handle H 332 soft pointer
758
                                this._writer.HandleReference(DwgReferenceType.SoftPointer, 0);
×
759
                                //Visual style H 348 hard pointer
760
                                this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
×
761
                                //Sun H 361 hard owner
762
                                this._writer.HandleReference(DwgReferenceType.HardOwnership, 0);
×
763
                        }
×
764

765
                        if (this.R2000Plus && view.IsUcsAssociated)
×
766
                        {
×
767
                                //TODO: Implement ucs reference for view
768
                                //Base UCS Handle H 346 hard pointer
769
                                this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
×
770
                                //Named UCS Handle H 345 hard pointer
771
                                this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
×
772
                        }
×
773

774
                        //R2007+:
775
                        if (this.R2007Plus)
×
776
                        {
×
777
                                //Live section H 334 soft pointer
778
                                this._writer.HandleReference(DwgReferenceType.SoftPointer, 0);
×
779
                        }
×
780

781
                        this.registerObject(view);
×
782
                }
×
783

784
                private void writeDimensionStyle(DimensionStyle dimStyle)
785
                {
38✔
786
                        this.writeCommonNonEntityData(dimStyle);
38✔
787

788
                        //Common:
789
                        //Entry name TV 2
790
                        this._writer.WriteVariableText(dimStyle.Name);
38✔
791

792
                        this.writeXrefDependantBit(dimStyle);
38✔
793

794
                        //R13 & R14 Only:
795
                        if (this.R13_14Only)
38✔
796
                        {
7✔
797
                                //DIMTOL B 71
798
                                this._writer.WriteBit(dimStyle.GenerateTolerances);
7✔
799
                                //DIMLIM B 72
800
                                this._writer.WriteBit(dimStyle.LimitsGeneration);
7✔
801
                                //DIMTIH B 73
802
                                this._writer.WriteBit(dimStyle.TextOutsideHorizontal);
7✔
803
                                //DIMTOH B 74
804
                                this._writer.WriteBit(dimStyle.SuppressFirstExtensionLine);
7✔
805
                                //DIMSE1 B 75
806
                                this._writer.WriteBit(dimStyle.SuppressSecondExtensionLine);
7✔
807
                                //DIMSE2 B 76
808
                                this._writer.WriteBit(dimStyle.TextInsideHorizontal);
7✔
809
                                //DIMALT B 170
810
                                this._writer.WriteBit(dimStyle.AlternateUnitDimensioning);
7✔
811
                                //DIMTOFL B 172
812
                                this._writer.WriteBit(dimStyle.TextOutsideExtensions);
7✔
813
                                //DIMSAH B 173
814
                                this._writer.WriteBit(dimStyle.SeparateArrowBlocks);
7✔
815
                                //DIMTIX B 174
816
                                this._writer.WriteBit(dimStyle.TextInsideExtensions);
7✔
817
                                //DIMSOXD B 175
818
                                this._writer.WriteBit(dimStyle.SuppressOutsideExtensions);
7✔
819
                                //DIMALTD RC 171
820
                                this._writer.WriteByte((byte)dimStyle.AlternateUnitDecimalPlaces);
7✔
821
                                //DIMZIN RC 78
822
                                this._writer.WriteByte((byte)dimStyle.ZeroHandling);
7✔
823
                                //DIMSD1 B 281
824
                                this._writer.WriteBit(dimStyle.SuppressFirstDimensionLine);
7✔
825
                                //DIMSD2 B 282
826
                                this._writer.WriteBit(dimStyle.SuppressSecondDimensionLine);
7✔
827
                                //DIMTOLJ RC 283
828
                                this._writer.WriteByte((byte)dimStyle.ToleranceAlignment);
7✔
829
                                //DIMJUST RC 280
830
                                this._writer.WriteByte((byte)dimStyle.TextHorizontalAlignment);
7✔
831
                                //DIMFIT RC 287
832
                                this._writer.WriteByte((byte)dimStyle.DimensionFit);
7✔
833
                                //DIMUPT B 288
834
                                this._writer.WriteBit(dimStyle.CursorUpdate);
7✔
835
                                //DIMTZIN RC 284
836
                                this._writer.WriteByte((byte)dimStyle.ToleranceZeroHandling);
7✔
837
                                //DIMALTZ RC 285
838
                                this._writer.WriteByte((byte)dimStyle.AlternateUnitZeroHandling);
7✔
839
                                //DIMALTTZ RC 286
840
                                this._writer.WriteByte((byte)dimStyle.AlternateUnitToleranceZeroHandling);
7✔
841
                                //DIMTAD RC 77
842
                                this._writer.WriteByte((byte)dimStyle.TextVerticalAlignment);
7✔
843
                                //DIMUNIT BS 270
844
                                this._writer.WriteBitShort(dimStyle.DimensionUnit);
7✔
845
                                //DIMAUNIT BS 275
846
                                this._writer.WriteBitShort((short)dimStyle.AngularUnit);
7✔
847
                                //DIMDEC BS 271
848
                                this._writer.WriteBitShort(dimStyle.DecimalPlaces);
7✔
849
                                //DIMTDEC BS 272
850
                                this._writer.WriteBitShort(dimStyle.ToleranceDecimalPlaces);
7✔
851
                                //DIMALTU BS 273
852
                                this._writer.WriteBitShort((short)dimStyle.AlternateUnitFormat);
7✔
853
                                //DIMALTTD BS 274
854
                                this._writer.WriteBitShort(dimStyle.AlternateUnitToleranceDecimalPlaces);
7✔
855
                                //DIMSCALE BD 40
856
                                this._writer.WriteBitDouble(dimStyle.ScaleFactor);
7✔
857
                                //DIMASZ BD 41
858
                                this._writer.WriteBitDouble(dimStyle.ArrowSize);
7✔
859
                                //DIMEXO BD 42
860
                                this._writer.WriteBitDouble(dimStyle.ExtensionLineOffset);
7✔
861
                                //DIMDLI BD 43
862
                                this._writer.WriteBitDouble(dimStyle.DimensionLineIncrement);
7✔
863
                                //DIMEXE BD 44
864
                                this._writer.WriteBitDouble(dimStyle.ExtensionLineExtension);
7✔
865
                                //DIMRND BD 45
866
                                this._writer.WriteBitDouble(dimStyle.Rounding);
7✔
867
                                //DIMDLE BD 46
868
                                this._writer.WriteBitDouble(dimStyle.DimensionLineExtension);
7✔
869
                                //DIMTP BD 47
870
                                this._writer.WriteBitDouble(dimStyle.PlusTolerance);
7✔
871
                                //DIMTM BD 48
872
                                this._writer.WriteBitDouble(dimStyle.MinusTolerance);
7✔
873
                                //DIMTXT BD 140
874
                                this._writer.WriteBitDouble(dimStyle.TextHeight);
7✔
875
                                //DIMCEN BD 141
876
                                this._writer.WriteBitDouble(dimStyle.CenterMarkSize);
7✔
877
                                //DIMTSZ BD 142
878
                                this._writer.WriteBitDouble(dimStyle.TickSize);
7✔
879
                                //DIMALTF BD 143
880
                                this._writer.WriteBitDouble(dimStyle.AlternateUnitScaleFactor);
7✔
881
                                //DIMLFAC BD 144
882
                                this._writer.WriteBitDouble(dimStyle.LinearScaleFactor);
7✔
883
                                //DIMTVP BD 145
884
                                this._writer.WriteBitDouble(dimStyle.TextVerticalPosition);
7✔
885
                                //DIMTFAC BD 146
886
                                this._writer.WriteBitDouble(dimStyle.ToleranceScaleFactor);
7✔
887
                                //DIMGAP BD 147
888
                                this._writer.WriteBitDouble(dimStyle.DimensionLineGap);
7✔
889

890
                                //DIMPOST T 3
891
                                this._writer.WriteVariableText(dimStyle.PostFix);
7✔
892
                                //DIMAPOST T 4
893
                                this._writer.WriteVariableText(dimStyle.AlternateDimensioningSuffix);
7✔
894

895
                                //DIMBLK T 5
896
                                this._writer.WriteVariableText(dimStyle.ArrowBlock?.Name);
7!
897
                                //DIMBLK1 T 6
898
                                this._writer.WriteVariableText(dimStyle.DimArrow1?.Name);
7!
899
                                //DIMBLK2 T 7
900
                                this._writer.WriteVariableText(dimStyle.DimArrow2?.Name);
7!
901

902
                                //DIMCLRD BS 176
903
                                this._writer.WriteCmColor(dimStyle.DimensionLineColor);
7✔
904
                                //DIMCLRE BS 177
905
                                this._writer.WriteCmColor(dimStyle.ExtensionLineColor);
7✔
906
                                //DIMCLRT BS 178
907
                                this._writer.WriteCmColor(dimStyle.TextColor);
7✔
908
                        }
7✔
909

910
                        //R2000+:
911
                        if (this.R2000Plus)
38✔
912
                        {
31✔
913
                                //DIMPOST TV 3
914
                                this._writer.WriteVariableText(dimStyle.PostFix);
31✔
915
                                //DIMAPOST TV 4
916
                                this._writer.WriteVariableText(dimStyle.AlternateDimensioningSuffix);
31✔
917
                                //DIMSCALE BD 40
918
                                this._writer.WriteBitDouble(dimStyle.ScaleFactor);
31✔
919
                                //DIMASZ BD 41
920
                                this._writer.WriteBitDouble(dimStyle.ArrowSize);
31✔
921
                                //DIMEXO BD 42
922
                                this._writer.WriteBitDouble(dimStyle.ExtensionLineOffset);
31✔
923
                                //DIMDLI BD 43
924
                                this._writer.WriteBitDouble(dimStyle.DimensionLineIncrement);
31✔
925
                                //DIMEXE BD 44
926
                                this._writer.WriteBitDouble(dimStyle.ExtensionLineExtension);
31✔
927
                                //DIMRND BD 45
928
                                this._writer.WriteBitDouble(dimStyle.Rounding);
31✔
929
                                //DIMDLE BD 46
930
                                this._writer.WriteBitDouble(dimStyle.DimensionLineExtension);
31✔
931
                                //DIMTP BD 47
932
                                this._writer.WriteBitDouble(dimStyle.PlusTolerance);
31✔
933
                                //DIMTM BD 48
934
                                this._writer.WriteBitDouble(dimStyle.MinusTolerance);
31✔
935
                        }
31✔
936

937
                        //R2007+:
938
                        if (this.R2007Plus)
38✔
939
                        {
20✔
940
                                //DIMFXL BD 49
941
                                this._writer.WriteBitDouble(dimStyle.FixedExtensionLineLength);
20✔
942
                                //DIMJOGANG BD 50
943
                                this._writer.WriteBitDouble(dimStyle.JoggedRadiusDimensionTransverseSegmentAngle);
20✔
944
                                //DIMTFILL BS 69
945
                                this._writer.WriteBitShort((short)dimStyle.TextBackgroundFillMode);
20✔
946
                                //DIMTFILLCLR CMC 70
947
                                this._writer.WriteCmColor(dimStyle.TextBackgroundColor);
20✔
948
                        }
20✔
949

950
                        //R2000+:
951
                        if (this.R2000Plus)
38✔
952
                        {
31✔
953
                                //DIMTOL B 71
954
                                this._writer.WriteBit(dimStyle.GenerateTolerances);
31✔
955
                                //DIMLIM B 72
956
                                this._writer.WriteBit(dimStyle.LimitsGeneration);
31✔
957
                                //DIMTIH B 73
958
                                this._writer.WriteBit(dimStyle.TextInsideHorizontal);
31✔
959
                                //DIMTOH B 74
960
                                this._writer.WriteBit(dimStyle.TextOutsideHorizontal);
31✔
961
                                //DIMSE1 B 75
962
                                this._writer.WriteBit(dimStyle.SuppressFirstExtensionLine);
31✔
963
                                //DIMSE2 B 76
964
                                this._writer.WriteBit(dimStyle.SuppressSecondExtensionLine);
31✔
965
                                //DIMTAD BS 77
966
                                this._writer.WriteBitShort((short)dimStyle.TextVerticalAlignment);
31✔
967
                                //DIMZIN BS 78
968
                                this._writer.WriteBitShort((short)dimStyle.ZeroHandling);
31✔
969
                                //DIMAZIN BS 79
970
                                this._writer.WriteBitShort((short)dimStyle.AngularZeroHandling);
31✔
971
                        }
31✔
972

973
                        //R2007 +:
974
                        if (this.R2007Plus)
38✔
975
                        {
20✔
976
                                //DIMARCSYM BS 90
977
                                this._writer.WriteBitShort((short)dimStyle.ArcLengthSymbolPosition);
20✔
978
                        }
20✔
979

980
                        //R2000 +:
981
                        if (this.R2000Plus)
38✔
982
                        {
31✔
983
                                //DIMTXT BD 140
984
                                this._writer.WriteBitDouble(dimStyle.TextHeight);
31✔
985
                                //DIMCEN BD 141
986
                                this._writer.WriteBitDouble(dimStyle.CenterMarkSize);
31✔
987
                                //DIMTSZ BD 142
988
                                this._writer.WriteBitDouble(dimStyle.TickSize);
31✔
989
                                //DIMALTF BD 143
990
                                this._writer.WriteBitDouble(dimStyle.AlternateUnitScaleFactor);
31✔
991
                                //DIMLFAC BD 144
992
                                this._writer.WriteBitDouble(dimStyle.LinearScaleFactor);
31✔
993
                                //DIMTVP BD 145                                                                                                                                                                          
994
                                this._writer.WriteBitDouble(dimStyle.TextVerticalPosition);
31✔
995
                                //DIMTFAC BD 146                                                                                                                                                                  
996
                                this._writer.WriteBitDouble(dimStyle.ToleranceScaleFactor);
31✔
997
                                //DIMGAP BD 147                                                                                                                                                                          
998
                                this._writer.WriteBitDouble(dimStyle.DimensionLineGap);
31✔
999
                                //DIMALTRND BD 148                                                                                                                                                                  
1000
                                this._writer.WriteBitDouble(dimStyle.AlternateUnitRounding);
31✔
1001
                                //DIMALT B 170                                                                                                                                                                          
1002
                                this._writer.WriteBit(dimStyle.AlternateUnitDimensioning);
31✔
1003
                                //DIMALTD BS 171                                                                                                                                                                  
1004
                                this._writer.WriteBitShort(dimStyle.AlternateUnitDecimalPlaces);
31✔
1005
                                //DIMTOFL B 172                                                                                                                                                                          
1006
                                this._writer.WriteBit(dimStyle.TextOutsideExtensions);
31✔
1007
                                //DIMSAH B 173                                                                                                                                                                          
1008
                                this._writer.WriteBit(dimStyle.SeparateArrowBlocks);
31✔
1009
                                //DIMTIX B 174                                                                                                                                                                          
1010
                                this._writer.WriteBit(dimStyle.TextInsideExtensions);
31✔
1011
                                //DIMSOXD B 175                                                                                                                                                                          
1012
                                this._writer.WriteBit(dimStyle.SuppressOutsideExtensions);
31✔
1013
                                //DIMCLRD BS 176                                                                                                                                                                  
1014
                                this._writer.WriteCmColor(dimStyle.DimensionLineColor);
31✔
1015
                                //DIMCLRE BS 177                                                                                                                                                                  
1016
                                this._writer.WriteCmColor(dimStyle.ExtensionLineColor);
31✔
1017
                                //DIMCLRT BS 178                                                                                                                                                                  
1018
                                this._writer.WriteCmColor(dimStyle.TextColor);
31✔
1019
                                //DIMADEC BS 179                                                                                                                                                                  
1020
                                this._writer.WriteBitShort(dimStyle.AngularDimensionDecimalPlaces);
31✔
1021
                                //DIMDEC BS 271                                                                                                                                                                          
1022
                                this._writer.WriteBitShort(dimStyle.DecimalPlaces);
31✔
1023
                                //DIMTDEC BS 272                                                                                                                                                                  
1024
                                this._writer.WriteBitShort(dimStyle.ToleranceDecimalPlaces);
31✔
1025
                                //DIMALTU BS 273                                                                                                                                                                  
1026
                                this._writer.WriteBitShort((short)dimStyle.AlternateUnitFormat);
31✔
1027
                                //DIMALTTD BS 274                                                                                                                                                                  
1028
                                this._writer.WriteBitShort(dimStyle.AlternateUnitToleranceDecimalPlaces);
31✔
1029
                                //DIMAUNIT BS 275                                                                                                                                                                  
1030
                                this._writer.WriteBitShort((short)dimStyle.AngularUnit);
31✔
1031
                                //DIMFRAC BS 276                                                                                                                                                                  
1032
                                this._writer.WriteBitShort((short)dimStyle.FractionFormat);
31✔
1033
                                //DIMLUNIT BS 277                                                                                                                                                                  
1034
                                this._writer.WriteBitShort((short)dimStyle.LinearUnitFormat);
31✔
1035
                                //DIMDSEP BS 278                                                                                                                                                                  
1036
                                this._writer.WriteBitShort((short)dimStyle.DecimalSeparator);
31✔
1037
                                //DIMTMOVE BS 279                                                                                                                                                                  
1038
                                this._writer.WriteBitShort((short)dimStyle.TextMovement);
31✔
1039
                                //DIMJUST BS 280                                                                                                                                                                  
1040
                                this._writer.WriteBitShort((short)dimStyle.TextHorizontalAlignment);
31✔
1041
                                //DIMSD1 B 281                                                                                                                                                                          
1042
                                this._writer.WriteBit(dimStyle.SuppressFirstDimensionLine);
31✔
1043
                                //DIMSD2 B 282                                                                                                                                                                          
1044
                                this._writer.WriteBit(dimStyle.SuppressSecondDimensionLine);
31✔
1045
                                //DIMTOLJ BS 283                                                                                                                                                                  
1046
                                this._writer.WriteBitShort((short)dimStyle.ToleranceAlignment);
31✔
1047
                                //DIMTZIN BS 284                                                                                                                                                                  
1048
                                this._writer.WriteBitShort((short)dimStyle.ToleranceZeroHandling);
31✔
1049
                                //DIMALTZ BS 285                                                                                                                                                                  
1050
                                this._writer.WriteBitShort((short)dimStyle.AlternateUnitZeroHandling);
31✔
1051
                                //DIMALTTZ BS 286                                                                                                                                                                  
1052
                                this._writer.WriteBitShort((short)dimStyle.AlternateUnitToleranceZeroHandling);
31✔
1053
                                //DIMUPT B 288                                                                                                                                                                          
1054
                                this._writer.WriteBit(dimStyle.CursorUpdate);
31✔
1055
                                //DIMFIT BS 287
1056
                                this._writer.WriteBitShort(3);
31✔
1057
                        }
31✔
1058

1059
                        //R2007+:
1060
                        if (this.R2007Plus)
38✔
1061
                        {
20✔
1062
                                //DIMFXLON B 290
1063
                                this._writer.WriteBit(dimStyle.IsExtensionLineLengthFixed);
20✔
1064
                        }
20✔
1065

1066
                        //R2010+:
1067
                        if (this.R2010Plus)
38✔
1068
                        {
18✔
1069
                                //DIMTXTDIRECTION B 295
1070
                                this._writer.WriteBit(dimStyle.TextDirection == TextDirection.RightToLeft);
18✔
1071
                                //DIMALTMZF BD ?
1072
                                this._writer.WriteBitDouble(dimStyle.AltMzf);
18✔
1073
                                //DIMALTMZS T ?
1074
                                this._writer.WriteVariableText(dimStyle.AltMzs);
18✔
1075
                                //DIMMZF BD ?
1076
                                this._writer.WriteBitDouble(dimStyle.Mzf);
18✔
1077
                                //DIMMZS T ?
1078
                                this._writer.WriteVariableText(dimStyle.Mzs);
18✔
1079
                        }
18✔
1080

1081
                        //R2000+:
1082
                        if (this.R2000Plus)
38✔
1083
                        {
31✔
1084
                                //DIMLWD BS 371
1085
                                this._writer.WriteBitShort((short)dimStyle.DimensionLineWeight);
31✔
1086
                                //DIMLWE BS 372
1087
                                this._writer.WriteBitShort((short)dimStyle.ExtensionLineWeight);
31✔
1088
                        }
31✔
1089

1090
                        //Common:
1091
                        //Unknown B 70 Seems to set the 0 - bit(1) of the 70 - group.
1092
                        this._writer.WriteBit(false);
38✔
1093

1094
                        //Handle refs H Dimstyle control(soft pointer)
1095
                        //[Reactors(soft pointer)]
1096
                        //xdicobjhandle(hard owner)
1097

1098
                        //External reference block handle(hard pointer)
1099
                        this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
38✔
1100

1101
                        //340 shapefile(DIMTXSTY)(hard pointer)
1102
                        this._writer.HandleReference(DwgReferenceType.HardPointer, dimStyle.Style);
38✔
1103

1104
                        //R2000+:
1105
                        if (this.R2000Plus)
38✔
1106
                        {
31✔
1107
                                //341 leader block(DIMLDRBLK) (hard pointer)
1108
                                this._writer.HandleReference(DwgReferenceType.HardPointer, dimStyle.LeaderArrow);
31✔
1109
                                //342 dimblk(DIMBLK)(hard pointer)
1110
                                this._writer.HandleReference(DwgReferenceType.HardPointer, dimStyle.ArrowBlock);
31✔
1111
                                //343 dimblk1(DIMBLK1)(hard pointer)
1112
                                this._writer.HandleReference(DwgReferenceType.HardPointer, dimStyle.DimArrow1);
31✔
1113
                                //344 dimblk2(DIMBLK2)(hard pointer)
1114
                                this._writer.HandleReference(DwgReferenceType.HardPointer, dimStyle.DimArrow2);
31✔
1115
                        }
31✔
1116

1117
                        //R2007+:
1118
                        if (this.R2007Plus)
38✔
1119
                        {
20✔
1120
                                //345 dimltype(hard pointer)
1121
                                this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
20✔
1122
                                //346 dimltex1(hard pointer)
1123
                                this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
20✔
1124
                                //347 dimltex2(hard pointer)
1125
                                this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
20✔
1126
                        }
20✔
1127

1128
                        this.registerObject(dimStyle);
38✔
1129
                }
38✔
1130

1131
                private void writeVPort(VPort vport)
1132
                {
38✔
1133
                        this.writeCommonNonEntityData(vport);
38✔
1134

1135
                        //Common:
1136
                        //Entry name TV 2
1137
                        this._writer.WriteVariableText(vport.Name);
38✔
1138

1139
                        this.writeXrefDependantBit(vport);
38✔
1140

1141
                        //View height BD 40
1142
                        this._writer.WriteBitDouble(vport.ViewHeight);
38✔
1143
                        //Aspect ratio BD 41 The number stored here is actually the aspect ratio times the view height (40),
1144
                        //so this number must be divided by the 40-value to produce the aspect ratio that entget gives.
1145
                        //(R13 quirk; R12 has just the aspect ratio.)
1146
                        this._writer.WriteBitDouble(vport.AspectRatio * vport.ViewHeight);
38✔
1147
                        //View Center 2RD 12 DCS. (If it's plan view, add the view target (17) to get the WCS coordinates.
1148
                        //Careful! Sometimes you have to SAVE/OPEN to update the .dwg file.) Note that it's WSC in R12.
1149
                        this._writer.Write2RawDouble(vport.Center);
38✔
1150
                        //View target 3BD 17
1151
                        this._writer.Write3BitDouble(vport.Target);
38✔
1152
                        //View dir 3BD 16
1153
                        this._writer.Write3BitDouble(vport.Direction);
38✔
1154
                        //View twist BD 51
1155
                        this._writer.WriteBitDouble(vport.TwistAngle);
38✔
1156
                        //Lens length BD 42
1157
                        this._writer.WriteBitDouble(vport.LensLength);
38✔
1158
                        //Front clip BD 43
1159
                        this._writer.WriteBitDouble(vport.FrontClippingPlane);
38✔
1160
                        //Back clip BD 44
1161
                        this._writer.WriteBitDouble(vport.BackClippingPlane);
38✔
1162

1163
                        //View mode X 71 4 bits: 0123
1164
                        //Note that only bits 0, 1, 2, and 4 are given here; see UCSFOLLOW below for bit 3(8) of the 71.
1165
                        //0 : 71's bit 0 (1)
1166
                        this._writer.WriteBit(vport.ViewMode.HasFlag(ViewModeType.PerspectiveView));
38✔
1167
                        //1 : 71's bit 1 (2)
1168
                        this._writer.WriteBit(vport.ViewMode.HasFlag(ViewModeType.FrontClipping));
38✔
1169
                        //2 : 71's bit 2 (4)
1170
                        this._writer.WriteBit(vport.ViewMode.HasFlag(ViewModeType.BackClipping));
38✔
1171
                        //3 : OPPOSITE of 71's bit 4 (16)
1172
                        this._writer.WriteBit(vport.ViewMode.HasFlag(ViewModeType.FrontClippingZ));
38✔
1173

1174
                        //R2000+:
1175
                        if (this.R2000Plus)
38✔
1176
                        {
31✔
1177
                                //Render Mode RC 281
1178
                                this._writer.WriteByte((byte)vport.RenderMode);
31✔
1179
                        }
31✔
1180

1181
                        //R2007+:
1182
                        if (this.R2007Plus)
38✔
1183
                        {
20✔
1184
                                //Use default lights B 292
1185
                                this._writer.WriteBit(vport.UseDefaultLighting);
20✔
1186
                                //Default lighting type RC 282
1187
                                this._writer.WriteByte((byte)vport.DefaultLighting);
20✔
1188
                                //Brightness BD 141
1189
                                this._writer.WriteBitDouble(vport.Brightness);
20✔
1190
                                //Constrast BD 142
1191
                                this._writer.WriteBitDouble(vport.Contrast);
20✔
1192
                                //Ambient Color CMC 63
1193
                                this._writer.WriteCmColor(vport.AmbientColor);
20✔
1194
                        }
20✔
1195

1196
                        //Common:
1197
                        //Lower left 2RD 10 In fractions of screen width and height.
1198
                        this._writer.Write2RawDouble(vport.BottomLeft);
38✔
1199
                        //Upper right 2RD 11 In fractions of screen width and height.
1200
                        this._writer.Write2RawDouble(vport.TopRight);
38✔
1201

1202
                        //UCSFOLLOW B 71 UCSFOLLOW. Bit 3 (8) of the 71-group.
1203
                        this._writer.WriteBit(vport.ViewMode.HasFlag(ViewModeType.Follow));
38✔
1204

1205
                        //Circle zoom BS 72 Circle zoom percent.
1206
                        this._writer.WriteBitShort(vport.CircleZoomPercent);
38✔
1207

1208
                        //Fast zoom B 73
1209
                        this._writer.WriteBit(true);
38✔
1210

1211
                        //UCSICON X 74 2 bits: 01
1212
                        //0 : 74's bit 0 (1)
1213
                        this._writer.WriteBit(vport.UcsIconDisplay.HasFlag(UscIconType.OnLower));
38✔
1214

1215
                        //1 : 74's bit 1 (2)
1216
                        this._writer.WriteBit(vport.UcsIconDisplay.HasFlag(UscIconType.OnOrigin));
38✔
1217

1218
                        //Grid on/off B 76
1219
                        this._writer.WriteBit(vport.ShowGrid);
38✔
1220
                        //Grd spacing 2RD 15
1221
                        this._writer.Write2RawDouble(vport.GridSpacing);
38✔
1222
                        //Snap on/off B 75
1223
                        this._writer.WriteBit(vport.SnapOn);
38✔
1224

1225
                        //Snap style B 77
1226
                        this._writer.WriteBit(vport.IsometricSnap);
38✔
1227

1228
                        //Snap isopair BS 78
1229
                        this._writer.WriteBitShort(vport.SnapIsoPair);
38✔
1230
                        //Snap rot BD 50
1231
                        this._writer.WriteBitDouble(vport.SnapRotation);
38✔
1232
                        //Snap base 2RD 13
1233
                        this._writer.Write2RawDouble(vport.SnapBasePoint);
38✔
1234
                        //Snp spacing 2RD 14
1235
                        this._writer.Write2RawDouble(vport.SnapSpacing);
38✔
1236

1237
                        //R2000+:
1238
                        if (this.R2000Plus)
38✔
1239
                        {
31✔
1240
                                //Unknown B
1241
                                this._writer.WriteBit(false);
31✔
1242

1243
                                //UCS per Viewport B 71
1244
                                this._writer.WriteBit(true);
31✔
1245
                                //UCS Origin 3BD 110
1246
                                this._writer.Write3BitDouble(vport.Origin);
31✔
1247
                                //UCS X Axis 3BD 111
1248
                                this._writer.Write3BitDouble(vport.XAxis);
31✔
1249
                                //UCS Y Axis 3BD 112
1250
                                this._writer.Write3BitDouble(vport.YAxis);
31✔
1251
                                //UCS Elevation BD 146
1252
                                this._writer.WriteBitDouble(vport.Elevation);
31✔
1253
                                //UCS Orthographic type BS 79
1254
                                this._writer.WriteBitShort((short)vport.OrthographicType);
31✔
1255
                        }
31✔
1256

1257
                        //R2007+:
1258
                        if (this.R2007Plus)
38✔
1259
                        {
20✔
1260
                                //Grid flags BS 60
1261
                                this._writer.WriteBitShort((short)vport.GridFlags);
20✔
1262
                                //Grid major BS 61
1263
                                this._writer.WriteBitShort(vport.MinorGridLinesPerMajorGridLine);
20✔
1264
                        }
20✔
1265

1266
                        //Common:
1267
                        //External reference block handle(hard pointer)
1268
                        this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
38✔
1269

1270
                        //R2007+:
1271
                        if (this.R2007Plus)
38✔
1272
                        {
20✔
1273
                                //Background handle H 332 soft pointer
1274
                                this._writer.HandleReference(DwgReferenceType.SoftPointer, 0);
20✔
1275
                                //Visual Style handle H 348 hard pointer
1276
                                this._writer.HandleReference(DwgReferenceType.SoftPointer, 0);
20✔
1277
                                //Sun handle H 361 hard owner
1278
                                this._writer.HandleReference(DwgReferenceType.SoftPointer, 0);
20✔
1279
                        }
20✔
1280

1281
                        //R2000+:
1282
                        if (this.R2000Plus)
38✔
1283
                        {
31✔
1284
                                if (vport.OrthographicType == OrthographicType.None)
31!
1285
                                {
31✔
1286
                                        //Named UCS Handle H 345 hard pointer
1287
                                        this._writer.HandleReference(DwgReferenceType.HardPointer, vport.NamedUcs);
31✔
1288
                                        //Base UCS Handle H 346 hard pointer
1289
                                        this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
31✔
1290
                                }
31✔
1291
                                else
1292
                                {
×
1293
                                        //Named UCS Handle H 345 hard pointer
1294
                                        this._writer.HandleReference(DwgReferenceType.HardPointer, 0);
×
1295
                                        //Base UCS Handle H 346 hard pointer
1296
                                        this._writer.HandleReference(DwgReferenceType.HardPointer, vport.BaseUcs);
×
1297
                                }
×
1298
                        }
31✔
1299

1300
                        this.registerObject(vport);
38✔
1301
                }
38✔
1302
        }
1303
}
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

© 2025 Coveralls, Inc