• 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

42.91
/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs
1
using ACadSharp.Objects;
2
using CSMath;
3
using CSUtilities.Converters;
4
using CSUtilities.IO;
5
using System;
6
using System.Collections.Generic;
7
using System.IO;
8
using System.Linq;
9

10
namespace ACadSharp.IO.DWG
11
{
12
        internal partial class DwgObjectWriter : DwgSectionIO
13
        {
14
                private void writeObjects()
15
                {
38✔
16
                        while (this._objects.Any())
1,406✔
17
                        {
1,368✔
18
                                CadObject obj = this._objects.Dequeue();
1,368✔
19

20
                                this.writeObject(obj);
1,368✔
21
                        }
1,368✔
22
                }
38✔
23

24
                private void writeObject(CadObject obj)
25
                {
1,368✔
26
                        switch (obj)
1,368✔
27
                        {
28
                                case Material:
29
                                case MultiLeaderAnnotContext:
30
                                case MultiLeaderStyle:
31
                                case SortEntitiesTable:
32
                                case UnknownNonGraphicalObject:
33
                                case VisualStyle:
34
                                        this.notify($"Object type not implemented {obj.GetType().FullName}", NotificationType.NotImplemented);
38✔
35
                                        return;
38✔
36
                        }
37

38
                        if (obj is XRecord && !this.WriteXRecords)
1,330!
39
                        {
×
40
                                return;
×
41
                        }
42

43
                        this.writeCommonNonEntityData(obj);
1,330✔
44

45
                        switch (obj)
1,330!
46
                        {
47
                                case AcdbPlaceHolder acdbPlaceHolder:
48
                                        this.writeAcdbPlaceHolder(acdbPlaceHolder);
×
49
                                        break;
×
50
                                case BookColor bookColor:
51
                                        this.writeBookColor(bookColor);
×
52
                                        break;
×
53
                                case CadDictionaryWithDefault dictionarydef:
54
                                        this.writeCadDictionaryWithDefault(dictionarydef);
×
55
                                        break;
×
56
                                case CadDictionary dictionary:
57
                                        this.writeDictionary(dictionary);
570✔
58
                                        break;
570✔
59
                                case DictionaryVariable dictionaryVariable:
60
                                        this.writeDictionaryVariable(dictionaryVariable);
×
61
                                        break;
×
62
                                case Group group:
63
                                        this.writeGroup(group);
×
64
                                        break;
×
65
                                case ImageDefinitionReactor definitionReactor:
66
                                        this.writeImageDefinitionReactor(definitionReactor);
×
67
                                        break;
×
68
                                case ImageDefinition definition:
69
                                        this.writeImageDefinition(definition);
×
70
                                        break;
×
71
                                case Layout layout:
72
                                        this.writeLayout(layout);
76✔
73
                                        break;
76✔
74
                                case MLineStyle style:
75
                                        this.writeMLineStyle(style);
38✔
76
                                        break;
38✔
77
                                case MultiLeaderStyle multiLeaderStyle:
78
                                        this.writeMultiLeaderStyle(multiLeaderStyle);
×
79
                                        break;
×
80
                                case PlotSettings plotsettings:
81
                                        this.writePlotSettings(plotsettings);
×
82
                                        break;
×
83
                                case Scale scale:
84
                                        this.writeScale(scale);
646✔
85
                                        break;
646✔
86
                                case SortEntitiesTable sorttables:
87
                                        this.writeSortEntitiesTable(sorttables);
×
88
                                        break;
×
89
                                case XRecord record:
90
                                        this.writeXRecord(record);
×
91
                                        break;
×
92
                                default:
93
                                        throw new NotImplementedException($"Object not implemented : {obj.GetType().FullName}");
×
94
                        }
95

96
                        this.registerObject(obj);
1,330✔
97
                }
1,368✔
98

99
                private void writeAcdbPlaceHolder(AcdbPlaceHolder acdbPlaceHolder)
100
                {
×
101
                }
×
102

103
                private void writeBookColor(BookColor color)
104
                {
×
105
                        this._writer.WriteBitShort(0);
×
106

107
                        if (this.R2004Plus)
×
108
                        {
×
109
                                byte[] arr = new byte[]
×
110
                                {
×
111
                                        color.Color.B,
×
112
                                        color.Color.G,
×
113
                                        color.Color.R,
×
114
                                        0b11000010
×
115
                                };
×
116

117
                                uint rgb = LittleEndianConverter.Instance.ToUInt32(arr);
×
118

119
                                this._writer.WriteBitLong((int)rgb);
×
120

121
                                byte flags = 0;
×
122
                                if (!string.IsNullOrEmpty(color.ColorName))
×
123
                                {
×
124
                                        flags = (byte)(flags | 1u);
×
125
                                }
×
126

127
                                if (!string.IsNullOrEmpty(color.BookName))
×
128
                                {
×
129
                                        flags = (byte)(flags | 2u);
×
130
                                }
×
131

132
                                this._writer.WriteByte(flags);
×
133
                                if (!string.IsNullOrEmpty(color.ColorName))
×
134
                                {
×
135
                                        this._writer.WriteVariableText(color.ColorName);
×
136
                                }
×
137

138
                                if (!string.IsNullOrEmpty(color.BookName))
×
139
                                {
×
140
                                        this._writer.WriteVariableText(color.BookName);
×
141
                                }
×
142
                        }
×
143
                }
×
144

145
                private void writeCadDictionaryWithDefault(CadDictionaryWithDefault dictionary)
146
                {
×
147
                        this.writeDictionary(dictionary);
×
148

149
                        //H 7 Default entry (hard pointer)
150
                        this._writer.HandleReference(DwgReferenceType.HardPointer, dictionary.DefaultEntry);
×
151
                }
×
152

153
                private void writeDictionary(CadDictionary dictionary)
154
                {
570✔
155
                        //Common:
156
                        //Numitems L number of dictionary items
157
                        List<NonGraphicalObject> entries = new List<NonGraphicalObject>();
570✔
158
                        foreach (var item in dictionary)
4,370✔
159
                        {
1,330✔
160
                                if (item is XRecord && !this.WriteXRecords)
1,330!
NEW
161
                                {
×
NEW
162
                                        continue;
×
163
                                }
164

165
                                if (item is UnknownNonGraphicalObject)
1,330!
NEW
166
                                {
×
NEW
167
                                        continue;
×
168
                                }
169

170
                                entries.Add(item);
1,330✔
171
                        }
1,330✔
172

173
                        //16
174
                        this._writer.WriteBitLong(entries.Count);
570✔
175

176
                        //R14 Only:
177
                        if (this._version == ACadVersion.AC1014)
570✔
178
                        {
75✔
179
                                //Unknown R14 RC Unknown R14 byte, has always been 0
180
                                this._writer.WriteByte(0);
75✔
181
                        }
75✔
182

183
                        //R2000 +:
184
                        if (this.R2000Plus)
570✔
185
                        {
465✔
186
                                //Cloning flag BS 281
187
                                this._writer.WriteBitShort((short)dictionary.ClonningFlags);
465✔
188
                                this._writer.WriteByte((byte)(dictionary.HardOwnerFlag ? 1u : 0u));
465!
189
                        }
465✔
190

191
                        //Common:
192
                        foreach (var item in entries)
4,370✔
193
                        {
1,330✔
194
                                if (item is XRecord && !this.WriteXRecords)
1,330!
195
                                {
×
NEW
196
                                        continue;
×
197
                                }
198

199
                                if (item is UnknownNonGraphicalObject)
1,330!
200
                                {
×
NEW
201
                                        continue;
×
202
                                }
203

204
                                this._writer.WriteVariableText(item.Name);
1,330✔
205
                                this._writer.HandleReference(DwgReferenceType.SoftOwnership, item.Handle);
1,330✔
206
                        }
1,330✔
207

208
                        this.addEntriesToWriter(dictionary);
570✔
209
                }
570✔
210

211
                private void addEntriesToWriter(CadDictionary dictionary)
212
                {
570✔
213
                        foreach (CadObject e in dictionary)
4,370✔
214
                        {
1,330✔
215
                                this._objects.Enqueue(e);
1,330✔
216
                        }
1,330✔
217
                }
570✔
218

219
                private void writeDictionaryVariable(DictionaryVariable dictionaryVariable)
220
                {
×
221
                        //Intval RC an integer value
222
                        this._writer.WriteByte(0);
×
223

224
                        //BS a string
225
                        this._writer.WriteVariableText(dictionaryVariable.Value);
×
226
                }
×
227

228
                private void writeGroup(Group group)
229
                {
×
230
                        //Str TV name of group
231
                        this._writer.WriteVariableText(group.Description);
×
232

233
                        //Unnamed BS 1 if group has no name
234
                        this._writer.WriteBitShort((short)(group.IsUnnamed ? 1 : 0));
×
235
                        //Selectable BS 1 if group selectable
236
                        this._writer.WriteBitShort((short)(group.Selectable ? 1 : 0));
×
237

238
                        //Numhandles BL # objhandles in this group
239
                        this._writer.WriteBitLong(group.Entities.Count);
×
240
                        foreach (ulong h in group.Entities.Keys)
×
241
                        {
×
242
                                //the entries in the group(hard pointer)
243
                                this._writer.HandleReference(DwgReferenceType.HardPointer, h);
×
244
                        }
×
245
                }
×
246

247
                private void writeImageDefinitionReactor(ImageDefinitionReactor definitionReactor)
248
                {
×
249
                        //Common:
250
                        //Classver BL 90 class version
251
                        this._writer.WriteBitLong(definitionReactor.ClassVersion);
×
252
                }
×
253

254
                private void writeImageDefinition(ImageDefinition definition)
255
                {
×
256
                        //Common:
257
                        //Clsver BL 0 class version
258
                        this._writer.WriteBitLong(definition.ClassVersion);
×
259
                        //Imgsize 2RD 10 size of image in pixels
260
                        this._writer.Write2RawDouble(definition.Size);
×
261
                        //Filepath TV 1 path to file
262
                        this._writer.WriteVariableText(definition.FileName);
×
263
                        //Isloaded B 280 0==no, 1==yes
264
                        this._writer.WriteBit(definition.IsLoaded);
×
265
                        //Resunits RC 281 0==none, 2==centimeters, 5==inches
266
                        this._writer.WriteByte((byte)definition.Units);
×
267
                        //Pixelsize 2RD 11 size of one pixel in AutoCAD units
268
                        this._writer.Write2RawDouble(definition.DefaultSize);
×
269
                }
×
270

271
                private void writeLayout(Layout layout)
272
                {
76✔
273
                        this.writePlotSettings(layout);
76✔
274

275
                        //Common:
276
                        //Layout name TV 1 layout name
277
                        this._writer.WriteVariableText(layout.Name);
76✔
278
                        //Tab order BL 71 layout tab order
279
                        this._writer.WriteBitLong(layout.TabOrder);
76✔
280
                        //Flag BS 70 layout flags
281
                        this._writer.WriteBitShort((short)layout.LayoutFlags);
76✔
282
                        //Ucs origin 3BD 13 layout ucs origin
283
                        this._writer.Write3BitDouble(layout.Origin);
76✔
284
                        //Limmin 2RD 10 layout minimum limits
285
                        this._writer.Write2RawDouble(layout.MinLimits);
76✔
286
                        //Limmax 2RD 11 layout maximum limits
287
                        this._writer.Write2RawDouble(layout.MinLimits);
76✔
288
                        //Inspoint 3BD 12 layout insertion base point
289
                        this._writer.Write3BitDouble(layout.InsertionBasePoint);
76✔
290
                        this._writer.Write3BitDouble(layout.XAxis);
76✔
291
                        this._writer.Write3BitDouble(layout.YAxis);
76✔
292
                        this._writer.WriteBitDouble(layout.Elevation);
76✔
293
                        this._writer.WriteBitShort((short)layout.UcsOrthographicType);
76✔
294
                        this._writer.Write3BitDouble(layout.MinExtents);
76✔
295
                        this._writer.Write3BitDouble(layout.MaxExtents);
76✔
296

297
                        //R2004 +:
298
                        if (this.R2004Plus)
76✔
299
                        {
52✔
300
                                //Viewport count RL # of viewports in this layout
301
                                this._writer.WriteBitLong(layout.Viewports.Count());
52✔
302
                        }
52✔
303

304
                        //Common:
305
                        //330 associated paperspace block record handle(soft pointer)
306
                        this._writer.HandleReference(DwgReferenceType.SoftPointer, layout.AssociatedBlock);
76✔
307
                        //331 last active viewport handle(soft pointer)
308
                        this._writer.HandleReference(DwgReferenceType.SoftPointer, layout.Viewport);
76✔
309

310
                        //If not present and 76 code is non-zero, then base UCS is taken to be WORLD
311
                        if (layout.UcsOrthographicType == OrthographicType.None)
76!
312
                        {
76✔
313
                                //346 base ucs handle(hard pointer)
314
                                this._writer.HandleReference(DwgReferenceType.HardPointer, null);
76✔
315
                                //345 named ucs handle(hard pointer)
316
                                this._writer.HandleReference(DwgReferenceType.HardPointer, layout.UCS);
76✔
317
                        }
76✔
318
                        else
319
                        {
×
320
                                //346 base ucs handle(hard pointer)
321
                                this._writer.HandleReference(DwgReferenceType.HardPointer, layout.BaseUCS);
×
322
                                //345 named ucs handle(hard pointer)
323
                                this._writer.HandleReference(DwgReferenceType.HardPointer, null);
×
324
                        }
×
325

326
                        //R2004+:
327
                        if (this.R2004Plus)
76✔
328
                        {
52✔
329
                                foreach (Entities.Viewport viewport in layout.Viewports)
156!
330
                                {
×
331
                                        //Viewport handle(repeats Viewport count times) (soft pointer)
332
                                        this._writer.HandleReference(DwgReferenceType.SoftPointer, viewport);
×
333
                                }
×
334
                        }
52✔
335
                }
76✔
336

337
                private void writeMLineStyle(MLineStyle mlineStyle)
338
                {
38✔
339
                        //Common:
340
                        //Name TV Name of this style
341
                        this._writer.WriteVariableText(mlineStyle.Name);
38✔
342
                        //Desc TV Description of this style
343
                        this._writer.WriteVariableText(mlineStyle.Description);
38✔
344

345
                        short flags = 0;
38✔
346
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.DisplayJoints))
38!
347
                        {
×
348
                                flags = (short)(flags | 1U);
×
349
                        }
×
350
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.FillOn))
38!
351
                        {
×
352
                                flags = (short)(flags | 2U);
×
353
                        }
×
354
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.StartSquareCap))
38!
355
                        {
×
356
                                flags = (short)(flags | 16U);
×
357
                        }
×
358
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.StartRoundCap))
38!
359
                        {
×
360
                                flags = (short)(flags | 0x20);
×
361
                        }
×
362
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.StartInnerArcsCap))
38!
363
                        {
×
364
                                flags = (short)(flags | 0x40);
×
365
                        }
×
366
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.EndSquareCap))
38!
367
                        {
×
368
                                flags = (short)(flags | 0x100);
×
369
                        }
×
370
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.EndRoundCap))
38!
371
                        {
×
372
                                flags = (short)(flags | 0x200);
×
373
                        }
×
374
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.EndInnerArcsCap))
38!
375
                        {
×
376
                                flags = (short)(flags | 0x400);
×
377
                        }
×
378

379
                        //Flags BS A short which reconstitutes the mlinestyle flags as defined in DXF.
380
                        this._writer.WriteBitShort(flags);
38✔
381

382
                        //fillcolor CMC Fill color for this style
383
                        this._writer.WriteCmColor(mlineStyle.FillColor);
38✔
384
                        //startang BD Start angle
385
                        this._writer.WriteBitDouble(mlineStyle.StartAngle);
38✔
386
                        //endang BD End angle
387
                        this._writer.WriteBitDouble(mlineStyle.EndAngle);
38✔
388

389
                        //linesinstyle RC Number of lines in this style
390
                        this._writer.WriteByte((byte)mlineStyle.Elements.Count);
38✔
391
                        foreach (MLineStyle.Element element in mlineStyle.Elements)
114!
392
                        {
×
393
                                //Offset BD Offset of this segment
394
                                this._writer.WriteBitDouble(element.Offset);
×
395
                                //Color CMC Color of this segment
396
                                this._writer.WriteCmColor(element.Color);
×
397
                                //R2018+:
398
                                if (this.R2018Plus)
×
399
                                {
×
400
                                        //Line type handle H Line type handle (hard pointer)
401
                                        this._writer.HandleReference(DwgReferenceType.HardPointer, element.LineType);
×
402
                                }
×
403
                                //Before R2018:
404
                                else
405
                                {
×
406
                                        //TODO: Fix the Linetype index for dwgReader and DwgWriter
407
                                        //Ltindex BS Linetype index (yes, index)
408
                                        this._writer.WriteBitShort(0);
×
409
                                }
×
410
                        }
×
411
                }
38✔
412

413
                private void writeMultiLeaderStyle(MultiLeaderStyle mLeaderStyle)
414
                {
×
415
                        //TODO: Remove this line when MultiLeaderStyle is fixed for writing
416
                        return;
×
417

418
                        if (!R2010Plus)
419
                        {
420
                                return;
421
                        }
422

423
                        //        BS        179        Version expected: 2
424
                        this._writer.WriteBitShort(2);
425

426
                        //        BS        170        Content type (see paragraph on LEADER for more details).
427
                        this._writer.WriteBitShort((short)mLeaderStyle.ContentType);
428
                        //        BS        171        Draw multi-leader order (0 = draw content first, 1 = draw leader first)
429
                        this._writer.WriteBitShort((short)mLeaderStyle.MultiLeaderDrawOrder);
430
                        //        BS        172        Draw leader order (0 = draw leader head first, 1 = draw leader tail first)
431
                        this._writer.WriteBitShort((short)mLeaderStyle.LeaderDrawOrder);
432
                        //        BL        90        Maximum number of points for leader
433
                        this._writer.WriteBitShort((short)mLeaderStyle.MaxLeaderSegmentsPoints);
434
                        //        BD        40        First segment angle (radians)
435
                        this._writer.WriteBitDouble(mLeaderStyle.FirstSegmentAngleConstraint);
436
                        //        BD        41        Second segment angle (radians)
437
                        this._writer.WriteBitDouble(mLeaderStyle.SecondSegmentAngleConstraint);
438
                        //        BS        173        Leader type (see paragraph on LEADER for more details).
439
                        this._writer.WriteBitShort((short)mLeaderStyle.PathType);
440
                        //        CMC        91        Leader line color
441
                        this._writer.WriteCmColor(mLeaderStyle.LineColor);
442
                        //        H        340        Leader line type handle (hard pointer)
443
                        this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.LeaderLineType);
444
                        //        BL        92        Leader line weight
445
                        this._writer.WriteBitLong((short)mLeaderStyle.LeaderLineWeight);
446
                        //        B        290        Is landing enabled?
447
                        this._writer.WriteBit(mLeaderStyle.EnableLanding);
448
                        //        BD        42        Landing gap
449
                        this._writer.WriteBitDouble(mLeaderStyle.LandingGap);
450
                        //        B        291        Auto include landing (is dog-leg enabled?)
451
                        this._writer.WriteBit(mLeaderStyle.EnableDogleg);
452
                        //        BD        43        Landing distance
453
                        this._writer.WriteBitDouble(mLeaderStyle.LandingDistance);
454
                        //        TV        3        Style description
455
                        this._writer.WriteVariableText(mLeaderStyle.Description);
456
                        //        H        341        Arrow head block handle (hard pointer)
457
                        this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.Arrowhead);
458
                        //        BD        44        Arrow head size
459
                        this._writer.WriteBitDouble(mLeaderStyle.ArrowheadSize);
460
                        //        TV        300        Text default
461
                        this._writer.WriteVariableText(mLeaderStyle.DefaultTextContents);
462
                        //        H        342        Text style handle (hard pointer)
463
                        this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.TextStyle);
464
                        //        BS        174        Left attachment (see paragraph on LEADER for more details).
465
                        this._writer.WriteBitShort((short)mLeaderStyle.TextLeftAttachment);
466
                        //        BS        178        Right attachment (see paragraph on LEADER for more details).
467
                        this._writer.WriteBitShort((short)mLeaderStyle.TextRightAttachment);
468
                        if (R2010Plus)
469
                        {
470
                                //        IF IsNewFormat OR DXF file
471
                                //        BS        175        Text angle type (see paragraph on LEADER for more details).
472
                                this._writer.WriteBitShort((short)mLeaderStyle.TextAngle);
473
                                //        END IF IsNewFormat OR DXF file
474
                        }
475
                        //        BS        176        Text alignment type
476
                        this._writer.WriteBitShort((short)mLeaderStyle.TextAlignment);
477
                        //        CMC        93        Text color
478
                        this._writer.WriteCmColor(mLeaderStyle.TextColor);
479
                        //        BD        45        Text height
480
                        this._writer.WriteBitDouble(mLeaderStyle.TextHeight);
481
                        //        B        292        Text frame enabled
482
                        this._writer.WriteBit(mLeaderStyle.TextFrame);
483
                        if (R2010Plus)
484
                        {
485
                                //        IF IsNewFormat OR DXF file
486
                                //        B        297        Always align text left
487
                                this._writer.WriteBit(mLeaderStyle.TextAlignAlwaysLeft);
488
                                //        END IF IsNewFormat OR DXF file
489
                        }
490
                        //        BD        46        Align space
491
                        this._writer.WriteBitDouble(mLeaderStyle.AlignSpace);
492
                        //        H        343        Block handle (hard pointer)
493
                        this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.BlockContent);
494
                        //        CMC        94        Block color
495
                        this._writer.WriteCmColor(mLeaderStyle.BlockContentColor);
496
                        //        3BD        47,49,140        Block scale vector
497
                        this._writer.Write3BitDouble(mLeaderStyle.BlockContentScale);
498
                        //        B        293        Is block scale enabled
499
                        this._writer.WriteBit(mLeaderStyle.EnableBlockContentScale);
500
                        //        BD        141        Block rotation (radians)
501
                        this._writer.WriteBitDouble(mLeaderStyle.BlockContentRotation);
502
                        //        B        294        Is block rotation enabled
503
                        this._writer.WriteBit(mLeaderStyle.EnableBlockContentRotation);
504
                        //        BS        177        Block connection type (0 = MLeader connects to the block extents, 1 = MLeader connects to the block base point)
505
                        this._writer.WriteBitShort((short)mLeaderStyle.BlockContentConnection);
506
                        //        BD        142        Scale factor
507
                        this._writer.WriteBitDouble(mLeaderStyle.ScaleFactor);
508
                        //        B        295        Property changed, meaning not totally clear
509
                        //        might be set to true if something changed after loading,
510
                        //        or might be used to trigger updates in dependent MLeaders.
511
                        //        sequence seems to be different in DXF
512
                        this._writer.WriteBit(mLeaderStyle.OverwritePropertyValue);
513
                        //        B        296        Is annotative?
514
                        this._writer.WriteBit(mLeaderStyle.IsAnnotative);
515
                        //        BD        143        Break size
516
                        this._writer.WriteBitDouble(mLeaderStyle.BreakGapSize);
517

518
                        //        BS        271        Attachment direction (see paragraph on LEADER for more details).
519
                        this._writer.WriteBitShort((short)mLeaderStyle.TextAttachmentDirection);
520
                        //        BS        273        Top attachment (see paragraph on LEADER for more details).
521
                        this._writer.WriteBitShort((short)mLeaderStyle.TextBottomAttachment);
522
                        //        BS        272        Bottom attachment (see paragraph on LEADER for more details).
523
                        this._writer.WriteBitShort((short)mLeaderStyle.TextTopAttachment);
524
                }
×
525

526
                private void writePlotSettings(PlotSettings plot)
527
                {
76✔
528
                        //Common:
529
                        //Page setup name TV 1 plotsettings page setup name
530
                        this._writer.WriteVariableText(plot.PageName);
76✔
531
                        //Printer / Config TV 2 plotsettings printer or configuration file
532
                        this._writer.WriteVariableText(plot.SystemPrinterName);
76✔
533
                        //Plot layout flags BS 70 plotsettings plot layout flag
534
                        this._writer.WriteBitShort((short)plot.Flags);
76✔
535

536
                        //Left Margin BD 40 plotsettings left margin in millimeters
537
                        this._writer.WriteBitDouble(plot.UnprintableMargin.Left);
76✔
538
                        //Bottom Margin BD 41 plotsettings bottom margin in millimeters
539
                        this._writer.WriteBitDouble(plot.UnprintableMargin.Bottom);
76✔
540
                        //Right Margin BD 42 plotsettings right margin in millimeters
541
                        this._writer.WriteBitDouble(plot.UnprintableMargin.Right);
76✔
542
                        //Top Margin BD 43 plotsettings top margin in millimeters
543
                        this._writer.WriteBitDouble(plot.UnprintableMargin.Top);
76✔
544

545
                        //Paper Width BD 44 plotsettings paper width in millimeters
546
                        this._writer.WriteBitDouble(plot.PaperWidth);
76✔
547
                        //Paper Height BD 45 plotsettings paper height in millimeters
548
                        this._writer.WriteBitDouble(plot.PaperHeight);
76✔
549

550
                        //Paper Size TV 4 plotsettings paper size
551
                        this._writer.WriteVariableText(plot.PaperSize);
76✔
552

553
                        //Plot origin 2BD 46,47 plotsettings origin offset in millimeters
554
                        this._writer.WriteBitDouble(plot.PlotOriginX);
76✔
555
                        this._writer.WriteBitDouble(plot.PlotOriginY);
76✔
556

557
                        //Paper units BS 72 plotsettings plot paper units
558
                        this._writer.WriteBitShort((short)plot.PaperUnits);
76✔
559
                        //Plot rotation BS 73 plotsettings plot rotation
560
                        this._writer.WriteBitShort((short)plot.PaperRotation);
76✔
561
                        //Plot type BS 74 plotsettings plot type
562
                        this._writer.WriteBitShort((short)plot.PlotType);
76✔
563

564
                        //Window min 2BD 48,49 plotsettings plot window area lower left
565
                        this._writer.WriteBitDouble(plot.WindowLowerLeftX);
76✔
566
                        this._writer.WriteBitDouble(plot.WindowLowerLeftY);
76✔
567
                        //Window max 2BD 140,141 plotsettings plot window area upper right
568
                        this._writer.WriteBitDouble(plot.WindowUpperLeftX);
76✔
569
                        this._writer.WriteBitDouble(plot.WindowUpperLeftY);
76✔
570

571
                        //R13 - R2000 Only:
572
                        if (this._version >= ACadVersion.AC1012 && this._version <= ACadVersion.AC1015)
76!
573
                        {
24✔
574
                                //Plot view name T 6 plotsettings plot view name
575
                                this._writer.WriteVariableText(plot.PlotViewName);
24✔
576
                        }
24✔
577

578
                        //Common:
579
                        //Real world units BD 142 plotsettings numerator of custom print scale
580
                        this._writer.WriteBitDouble(plot.NumeratorScale);
76✔
581
                        //Drawing units BD 143 plotsettings denominator of custom print scale
582
                        this._writer.WriteBitDouble(plot.DenominatorScale);
76✔
583
                        //Current style sheet TV 7 plotsettings current style sheet
584
                        this._writer.WriteVariableText(plot.StyleSheet);
76✔
585
                        //Scale type BS 75 plotsettings standard scale type
586
                        this._writer.WriteBitShort((short)plot.ScaledFit);
76✔
587
                        //Scale factor BD 147 plotsettings scale factor
588
                        this._writer.WriteBitDouble(plot.StandardScale);
76✔
589
                        //Paper image origin 2BD 148,149 plotsettings paper image origin
590
                        this._writer.Write2BitDouble(plot.PaperImageOrigin);
76✔
591

592
                        //R2004+:
593
                        if (this.R2004Plus)
76✔
594
                        {
52✔
595
                                //Shade plot mode BS 76
596
                                this._writer.WriteBitShort((short)plot.ShadePlotMode);
52✔
597
                                //Shade plot res.Level BS 77
598
                                this._writer.WriteBitShort((short)plot.ShadePlotResolutionMode);
52✔
599
                                //Shade plot custom DPI BS 78
600
                                this._writer.WriteBitShort(plot.ShadePlotDPI);
52✔
601

602
                                //6 plot view handle(hard pointer)
603
                                this._writer.HandleReference(DwgReferenceType.HardPointer, null);
52✔
604
                        }
52✔
605

606
                        //R2007 +:
607
                        if (this.R2007Plus)
76✔
608
                        {
40✔
609
                                //Visual Style handle(soft pointer)
610
                                this._writer.HandleReference(DwgReferenceType.SoftPointer, null);
40✔
611
                        }
40✔
612
                }
76✔
613

614
                private void writeScale(Scale scale)
615
                {
646✔
616
                        //BS        70        Unknown(ODA writes 0).
617
                        this._writer.WriteBitShort(0);
646✔
618
                        //TV        300        Name
619
                        this._writer.WriteVariableText(scale.Name);
646✔
620
                        //BD        140        Paper units(numerator)
621
                        this._writer.WriteBitDouble(scale.PaperUnits);
646✔
622
                        //BD        141        Drawing units(denominator, divided by 10).
623
                        this._writer.WriteBitDouble(scale.DrawingUnits);
646✔
624
                        //B        290        Has unit scale
625
                        this._writer.WriteBit(scale.IsUnitScale);
646✔
626
                }
646✔
627

628
                private void writeSortEntitiesTable(SortEntitiesTable sortEntitiesTable)
629
                {
×
630
                        //parenthandle (soft pointer)
631
                        this._writer.HandleReference(DwgReferenceType.SoftPointer, sortEntitiesTable.BlockOwner);
×
632

633
                        //Common:
634
                        //Numentries BL number of entries
635
                        this._writer.WriteBitLong(sortEntitiesTable.Sorters.Count());
×
636

637
                        foreach (var item in sortEntitiesTable.Sorters)
×
638
                        {
×
639
                                //Sort handle(numentries of these, CODE 0, i.e.part of the main bit stream, not of the handle bit stream!).
640
                                //The sort handle does not have to point to an entity (but it can).
641
                                //This is just the handle used for determining the drawing order of the entity specified by the entity handle in the handle bit stream.
642
                                //When the sortentstable doesn’t have a
643
                                //mapping from entity handle to sort handle, then the entity’s own handle is used for sorting.
644
                                this._writer.HandleReference(item.Handle);
×
645
                                this._writer.HandleReference(DwgReferenceType.SoftPointer, item.Entity);
×
646
                        }
×
647
                }
×
648

649
                private void writeXRecord(XRecord xrecord)
650
                {
×
651
                        MemoryStream stream = new MemoryStream();
×
652
                        StreamIO ms = new StreamIO(stream);
×
653
                        ms.EndianConverter = new LittleEndianConverter();
×
654

655
                        foreach (XRecord.Entry entry in xrecord.Entries)
×
656
                        {
×
657
                                if (entry.Value == null)
×
658
                                {
×
659
                                        continue;
×
660
                                }
661

662
                                ms.Write<short>((short)entry.Code);
×
663
                                GroupCodeValueType groupValueType = GroupCodeValue.TransformValue(entry.Code);
×
664

665
                                switch (groupValueType)
×
666
                                {
667
                                        case GroupCodeValueType.Byte:
668
                                        case GroupCodeValueType.Bool:
669
                                                ms.Write(Convert.ToByte(entry.Value, System.Globalization.CultureInfo.InvariantCulture));
×
670
                                                break;
×
671
                                        case GroupCodeValueType.Int16:
672
                                        case GroupCodeValueType.ExtendedDataInt16:
673
                                                ms.Write(Convert.ToInt16(entry.Value, System.Globalization.CultureInfo.InvariantCulture));
×
674
                                                break;
×
675
                                        case GroupCodeValueType.Int32:
676
                                        case GroupCodeValueType.ExtendedDataInt32:
677
                                                ms.Write(Convert.ToInt32(entry.Value, System.Globalization.CultureInfo.InvariantCulture));
×
678
                                                break;
×
679
                                        case GroupCodeValueType.Int64:
680
                                                ms.Write(Convert.ToInt64(entry.Value, System.Globalization.CultureInfo.InvariantCulture));
×
681
                                                break;
×
682
                                        case GroupCodeValueType.Double:
683
                                        case GroupCodeValueType.ExtendedDataDouble:
684
                                                double d = (entry.Value as double?).Value;
×
685
                                                ms.Write<double, LittleEndianConverter>(d);
×
686
                                                break;
×
687
                                        case GroupCodeValueType.Point3D:
688
                                                XYZ xyz = (entry.Value as XYZ?).Value;
×
689
                                                ms.Write<double, LittleEndianConverter>(xyz.X);
×
690
                                                ms.Write<double, LittleEndianConverter>(xyz.Y);
×
691
                                                ms.Write<double, LittleEndianConverter>(xyz.Z);
×
692
                                                break;
×
693
                                        case GroupCodeValueType.Chunk:
694
                                        case GroupCodeValueType.ExtendedDataChunk:
695
                                                byte[] array = (byte[])entry.Value;
×
696
                                                ms.Write((byte)array.Length);
×
697
                                                ms.WriteBytes(array);
×
698
                                                break;
×
699
                                        case GroupCodeValueType.String:
700
                                        case GroupCodeValueType.ExtendedDataString:
701
                                        case GroupCodeValueType.Handle:
702
                                                string text = (string)entry.Value;
×
703

704
                                                if (this.R2007Plus)
×
705
                                                {
×
706
                                                        if (string.IsNullOrEmpty(text))
×
707
                                                        {
×
708
                                                                ms.Write<short, LittleEndianConverter>(0);
×
709
                                                                return;
×
710
                                                        }
711

712
                                                        ms.Write<short, LittleEndianConverter>((short)text.Length);
×
713
                                                        ms.Write(text, System.Text.Encoding.Unicode);
×
714
                                                }
×
715
                                                else if (string.IsNullOrEmpty(text))
×
716
                                                {
×
717
                                                        ms.Write<short, LittleEndianConverter>(0);
×
718
                                                        ms.Write((byte)this._writer.Encoding.CodePage);
×
719
                                                }
×
720
                                                else
721
                                                {
×
722
                                                        ms.Write<short, LittleEndianConverter>((short)text.Length);
×
723
                                                        ms.Write((byte)this._writer.Encoding.CodePage);
×
724
                                                        ms.Write(text, this._writer.Encoding);
×
725
                                                }
×
726
                                                break;
×
727
                                        case GroupCodeValueType.ObjectId:
728
                                        case GroupCodeValueType.ExtendedDataHandle:
729
                                                ulong u = (entry.Value as ulong?).Value;
×
730
                                                ms.Write<ulong, LittleEndianConverter>(u);
×
731
                                                break;
×
732
                                        default:
733
                                                throw new NotSupportedException();
×
734
                                }
735
                        }
×
736

737
                        //Common:
738
                        //Numdatabytes BL number of databytes
739
                        this._writer.WriteBitLong((int)ms.Length);
×
740
                        this._writer.WriteBytes(stream.GetBuffer());
×
741

742
                        //R2000+:
743
                        if (this.R2000Plus)
×
744
                        {
×
745
                                //Cloning flag BS 280
746
                                this._writer.WriteBitShort((short)xrecord.CloningFlags);
×
747
                        }
×
748

749
                }
×
750
        }
751
}
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