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

DomCR / ACadSharp / 12008475829

25 Nov 2024 10:52AM UTC coverage: 75.339% (-0.3%) from 75.668%
12008475829

push

github

web-flow
Merge pull request #494 from DomCR/Issue-487_DBCOLOR

Issue 487 dbcolor

4956 of 7275 branches covered (68.12%)

Branch coverage included in aggregate %.

116 of 206 new or added lines in 21 files covered. (56.31%)

91 existing lines in 11 files now uncovered.

19811 of 25599 relevant lines covered (77.39%)

36312.43 hits per line

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

75.65
/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfObjectsSectionWriter.cs
1
using ACadSharp.Entities;
2
using ACadSharp.Objects;
3
using CSUtilities.Converters;
4
using System;
5
using System.Linq;
6

7
namespace ACadSharp.IO.DXF
8
{
9
        internal class DxfObjectsSectionWriter : DxfSectionWriterBase
10
        {
11
                public override string SectionName { get { return DxfFileToken.ObjectsSection; } }
135✔
12

13
                public bool WriteXRecords { get; set; } = false;
431✔
14

15
                public DxfObjectsSectionWriter(IDxfStreamWriter writer, CadDocument document, CadObjectHolder holder) : base(writer, document, holder)
45✔
16
                {
45✔
17
                }
45✔
18

19
                protected override void writeSection()
20
                {
45✔
21
                        while (this.Holder.Objects.Any())
1,984✔
22
                        {
1,939✔
23
                                CadObject item = this.Holder.Objects.Dequeue();
1,939✔
24

25
                                this.writeObject(item);
1,939✔
26
                        }
1,939✔
27
                }
45✔
28

29
                protected void writeObject<T>(T co)
30
                        where T : CadObject
31
                {
1,939✔
32
                        switch (co)
1,939!
33
                        {
34
                                case AcdbPlaceHolder:
35
                                case Material:
36
                                case MultiLeaderAnnotContext:
37
                                case VisualStyle:
38
                                case ImageDefinitionReactor:
39
                                case UnknownNonGraphicalObject:
40
                                case XRecord:
41
                                        this.notify($"Object not implemented : {co.GetType().FullName}");
×
42
                                        return;
×
43
                        }
44

45

46
                        if (co is XRecord && !this.WriteXRecords)
1,939!
47
                        {
×
48
                                return;
×
49
                        }
50

51
                        this._writer.Write(DxfCode.Start, co.ObjectName);
1,939✔
52

53
                        this.writeCommonObjectData(co);
1,939✔
54

55
                        switch (co)
1,939!
56
                        {
57
                                case BookColor bookColor:
NEW
58
                                        this.writeBookColor(bookColor);
×
NEW
59
                                        return;
×
60
                                case CadDictionary cadDictionary:
61
                                        this.writeDictionary(cadDictionary);
1,383✔
62
                                        return;
1,383✔
63
                                case DictionaryVariable dictvar:
64
                                        this.writeDictionaryVariable(dictvar);
×
65
                                        break;
×
66
                                case Group group:
67
                                        this.writeGroup(group);
×
68
                                        break;
×
69
                                case ImageDefinition imageDefinition:
70
                                        this.writeImageDefinition(imageDefinition);
7✔
71
                                        return;
7✔
72
                                case Layout layout:
73
                                        this.writeLayout(layout);
50✔
74
                                        break;
50✔
75
                                case MLineStyle mlStyle:
76
                                        this.writeMLineStyle(mlStyle);
25✔
77
                                        break;
25✔
78
                                case MultiLeaderStyle multiLeaderlStyle:
79
                                        this.writeMultiLeaderStyle(multiLeaderlStyle);
25✔
80
                                        break;
25✔
81
                                case PlotSettings plotSettings:
82
                                        this.writePlotSettings(plotSettings);
×
83
                                        break;
×
84
                                case Scale scale:
85
                                        this.writeScale(scale);
425✔
86
                                        break;
425✔
87
                                case SortEntitiesTable sortensTable:
88
                                        this.writeSortentsTable(sortensTable);
24✔
89
                                        break;
24✔
90
                                case XRecord record:
91
                                        this.writeXRecord(record);
×
92
                                        break;
×
93
                                default:
94
                                        throw new NotImplementedException($"Object not implemented : {co.GetType().FullName}");
×
95
                        }
96

97
                        this.writeExtendedData(co);
549✔
98
                }
1,939✔
99

100
                protected void writeBookColor(BookColor color)
NEW
101
                {
×
NEW
102
                        this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.DbColor);
×
103

NEW
104
                        this._writer.Write(62, color.Color.GetApproxIndex());
×
NEW
105
                        this._writer.WriteTrueColor(420, color.Color);
×
NEW
106
                        this._writer.Write(430, color.Name);
×
NEW
107
                }
×
108

109
                protected void writeDictionary(CadDictionary e)
110
                {
1,383✔
111
                        this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Dictionary);
1,383✔
112

113
                        this._writer.Write(280, e.HardOwnerFlag);
1,383✔
114
                        this._writer.Write(281, (int)e.ClonningFlags);
1,383✔
115

116
                        foreach (NonGraphicalObject item in e)
6,798✔
117
                        {
1,495✔
118
                                if (item is XRecord && !this.WriteXRecords)
1,495✔
119
                                {
341✔
120
                                        return;
341✔
121
                                }
122

123
                                this._writer.Write(3, item.Name);
1,154✔
124
                                this._writer.Write(350, item.Handle);
1,154✔
125
                        }
1,154✔
126

127
                        //Add the entries as objects
128
                        foreach (CadObject item in e)
5,432✔
129
                        {
1,153✔
130
                                this.Holder.Objects.Enqueue(item);
1,153✔
131
                        }
1,153✔
132
                }
1,383✔
133

134
                protected void writeDictionaryVariable(DictionaryVariable dictvar)
135
                {
×
136
                        DxfClassMap map = DxfClassMap.Create<DictionaryVariable>();
×
137

138
                        this._writer.Write(100, DxfSubclassMarker.DictionaryVariables);
×
139

140
                        this._writer.Write(1, dictvar.Value, map);
×
141
                        this._writer.Write(280, dictvar.ObjectSchemaNumber, map);
×
142
                }
×
143

144
                protected void writePlotSettings(PlotSettings plot)
145
                {
50✔
146
                        DxfClassMap map = DxfClassMap.Create<PlotSettings>();
50✔
147

148
                        this._writer.Write(100, DxfSubclassMarker.PlotSettings);
50✔
149

150
                        this._writer.Write(1, plot.PageName, map);
50✔
151
                        this._writer.Write(2, plot.SystemPrinterName, map);
50✔
152

153
                        this._writer.Write(4, plot.PaperSize, map);
50✔
154

155
                        this._writer.Write(6, plot.PlotViewName, map);
50✔
156
                        this._writer.Write(7, plot.StyleSheet, map);
50✔
157

158
                        this._writer.Write(40, plot.UnprintableMargin.Left, map);
50✔
159
                        this._writer.Write(41, plot.UnprintableMargin.Bottom, map);
50✔
160
                        this._writer.Write(42, plot.UnprintableMargin.Right, map);
50✔
161
                        this._writer.Write(43, plot.UnprintableMargin.Top, map);
50✔
162
                        this._writer.Write(44, plot.PaperWidth, map);
50✔
163
                        this._writer.Write(45, plot.PaperHeight, map);
50✔
164
                        this._writer.Write(46, plot.PlotOriginX, map);
50✔
165
                        this._writer.Write(47, plot.PlotOriginY, map);
50✔
166
                        this._writer.Write(48, plot.WindowLowerLeftX, map);
50✔
167
                        this._writer.Write(49, plot.WindowLowerLeftY, map);
50✔
168

169
                        this._writer.Write(140, plot.WindowUpperLeftX, map);
50✔
170
                        this._writer.Write(141, plot.WindowUpperLeftY, map);
50✔
171
                        this._writer.Write(142, plot.NumeratorScale, map);
50✔
172
                        this._writer.Write(143, plot.DenominatorScale, map);
50✔
173

174
                        this._writer.Write(70, (short)plot.Flags, map);
50✔
175

176
                        this._writer.Write(72, (short)plot.PaperUnits, map);
50✔
177
                        this._writer.Write(73, (short)plot.PaperRotation, map);
50✔
178
                        this._writer.Write(74, (short)plot.PlotType, map);
50✔
179
                        this._writer.Write(75, plot.ScaledFit, map);
50✔
180
                        this._writer.Write(76, (short)plot.ShadePlotMode, map);
50✔
181
                        this._writer.Write(77, (short)plot.ShadePlotResolutionMode, map);
50✔
182
                        this._writer.Write(78, plot.ShadePlotDPI, map);
50✔
183
                        this._writer.Write(147, plot.PrintScale, map);
50✔
184

185
                        this._writer.Write(148, plot.PaperImageOrigin.X, map);
50✔
186
                        this._writer.Write(149, plot.PaperImageOrigin.Y, map);
50✔
187
                }
50✔
188

189
                protected void writeScale(Scale scale)
190
                {
425✔
191
                        this._writer.Write(100, DxfSubclassMarker.Scale);
425✔
192

193
                        this._writer.Write(70, 0);
425✔
194
                        this._writer.Write(300, scale.Name);
425✔
195
                        this._writer.Write(140, scale.PaperUnits);
425✔
196
                        this._writer.Write(141, scale.DrawingUnits);
425✔
197
                        this._writer.Write(290, scale.IsUnitScale ? (short)1 : (short)0);
425✔
198
                }
425✔
199

200
                protected void writeGroup(Group group)
201
                {
×
202
                        this._writer.Write(100, DxfSubclassMarker.Group);
×
203

204
                        this._writer.Write(300, group.Description);
×
205
                        this._writer.Write(70, group.IsUnnamed ? (short)1 : (short)0);
×
206
                        this._writer.Write(71, group.Selectable ? (short)1 : (short)0);
×
207

208
                        foreach (Entity entity in group.Entities.Values)
×
209
                        {
×
210
                                this._writer.WriteHandle(340, entity);
×
211
                        }
×
212
                }
×
213

214
                protected void writeImageDefinition(ImageDefinition definition)
215
                {
7✔
216
                        DxfClassMap map = DxfClassMap.Create<ImageDefinition>();
7✔
217

218
                        this._writer.Write(100, DxfSubclassMarker.RasterImageDef);
7✔
219

220
                        this._writer.Write(90, definition.ClassVersion, map);
7✔
221
                        this._writer.Write(1, definition.FileName, map);
7✔
222

223
                        this._writer.Write(10, definition.Size, map);
7✔
224

225
                        this._writer.Write(280, definition.IsLoaded ? 1 : 0, map);
7!
226

227
                        this._writer.Write(281, (byte)definition.Units, map);
7✔
228
                }
7✔
229

230
                protected void writeLayout(Layout layout)
231
                {
50✔
232
                        DxfClassMap map = DxfClassMap.Create<Layout>();
50✔
233

234
                        this.writePlotSettings(layout);
50✔
235

236
                        this._writer.Write(100, DxfSubclassMarker.Layout);
50✔
237

238
                        this._writer.Write(1, layout.Name, map);
50✔
239

240
                        //this._writer.Write(70, (short) 1,map);
241
                        this._writer.Write(71, layout.TabOrder, map);
50✔
242

243
                        this._writer.Write(10, layout.MinLimits, map);
50✔
244
                        this._writer.Write(11, layout.MaxLimits, map);
50✔
245
                        this._writer.Write(12, layout.InsertionBasePoint, map);
50✔
246
                        this._writer.Write(13, layout.Origin, map);
50✔
247
                        this._writer.Write(14, layout.MinExtents, map);
50✔
248
                        this._writer.Write(15, layout.MaxExtents, map);
50✔
249
                        this._writer.Write(16, layout.XAxis, map);
50✔
250
                        this._writer.Write(17, layout.YAxis, map);
50✔
251

252
                        this._writer.Write(146, layout.Elevation, map);
50✔
253

254
                        this._writer.Write(76, (short)0, map);
50✔
255

256
                        this._writer.WriteHandle(330, layout.AssociatedBlock, map);
50✔
257
                }
50✔
258

259
                protected void writeMLineStyle(MLineStyle style)
260
                {
25✔
261
                        DxfClassMap map = DxfClassMap.Create<MLineStyle>();
25✔
262

263
                        this._writer.Write(100, DxfSubclassMarker.MLineStyle);
25✔
264

265
                        this._writer.Write(2, style.Name, map);
25✔
266

267
                        this._writer.Write(70, (short)style.Flags, map);
25✔
268

269
                        this._writer.Write(3, style.Description, map);
25✔
270

271
                        this._writer.Write(62, style.FillColor.GetApproxIndex(), map);
25✔
272

273
                        this._writer.Write(51, style.StartAngle, map);
25✔
274
                        this._writer.Write(52, style.EndAngle, map);
25✔
275
                        this._writer.Write(71, (short)style.Elements.Count, map);
25✔
276
                        foreach (MLineStyle.Element element in style.Elements)
75!
277
                        {
×
278
                                this._writer.Write(49, element.Offset, map);
×
279
                                this._writer.Write(62, element.Color.Index, map);
×
280
                                this._writer.Write(6, element.LineType.Name, map);
×
281
                        }
×
282
                }
25✔
283

284
                protected void writeMultiLeaderStyle(MultiLeaderStyle style)
285
                {
25✔
286
                        DxfClassMap map = DxfClassMap.Create<MultiLeaderStyle>();
25✔
287

288
                        this._writer.Write(100, DxfSubclassMarker.MLeaderStyle);
25✔
289

290
                        this._writer.Write(179, 2);
25✔
291
                        //        this._writer.Write(2, style.Name, map);
292
                        this._writer.Write(170, (short)style.ContentType, map);
25✔
293
                        this._writer.Write(171, (short)style.MultiLeaderDrawOrder, map);
25✔
294
                        this._writer.Write(172, (short)style.LeaderDrawOrder, map);
25✔
295
                        this._writer.Write(90, style.MaxLeaderSegmentsPoints, map);
25✔
296
                        this._writer.Write(40, style.FirstSegmentAngleConstraint, map);
25✔
297
                        this._writer.Write(41, style.SecondSegmentAngleConstraint, map);
25✔
298
                        this._writer.Write(173, (short)style.PathType, map);
25✔
299
                        this._writer.WriteCmColor(91, style.LineColor, map);
25✔
300
                        this._writer.WriteHandle(340, style.LeaderLineType);
25✔
301
                        this._writer.Write(92, (short)style.LeaderLineWeight, map);
25✔
302
                        this._writer.Write(290, style.EnableLanding, map);
25✔
303
                        this._writer.Write(42, style.LandingGap, map);
25✔
304
                        this._writer.Write(291, style.EnableDogleg, map);
25✔
305
                        this._writer.Write(43, style.LandingDistance, map);
25✔
306
                        this._writer.Write(3, style.Description, map);
25✔
307
                        this._writer.WriteHandle(341, style.Arrowhead);
25✔
308
                        this._writer.Write(44, style.ArrowheadSize, map);
25✔
309
                        this._writer.Write(300, style.DefaultTextContents, map);
25✔
310
                        this._writer.WriteHandle(342, style.TextStyle);
25✔
311
                        this._writer.Write(174, (short)style.TextLeftAttachment, map);
25✔
312
                        this._writer.Write(178, (short)style.TextRightAttachment, map);
25✔
313
                        this._writer.Write(175, style.TextAngle, map);
25✔
314
                        this._writer.Write(176, (short)style.TextAlignment, map);
25✔
315
                        this._writer.WriteCmColor(93, style.TextColor, map);
25✔
316
                        this._writer.Write(45, style.TextHeight, map);
25✔
317
                        this._writer.Write(292, style.TextFrame, map);
25✔
318
                        this._writer.Write(297, style.TextAlignAlwaysLeft, map);
25✔
319
                        this._writer.Write(46, style.AlignSpace, map);
25✔
320
                        this._writer.WriteHandle(343, style.BlockContent);
25✔
321
                        this._writer.WriteCmColor(94, style.BlockContentColor, map);
25✔
322

323
                        //        Write 3 doubles since group codes do not conform vector group codes
324
                        this._writer.Write(47, style.BlockContentScale.X, map);
25✔
325
                        this._writer.Write(49, style.BlockContentScale.Y, map);
25✔
326
                        this._writer.Write(140, style.BlockContentScale.Z, map);
25✔
327

328
                        this._writer.Write(293, style.EnableBlockContentScale, map);
25✔
329
                        this._writer.Write(141, style.BlockContentRotation, map);
25✔
330
                        this._writer.Write(294, style.EnableBlockContentRotation, map);
25✔
331
                        this._writer.Write(177, (short)style.BlockContentConnection, map);
25✔
332
                        this._writer.Write(142, style.ScaleFactor, map);
25✔
333
                        this._writer.Write(295, style.OverwritePropertyValue, map);
25✔
334
                        this._writer.Write(296, style.IsAnnotative, map);
25✔
335
                        this._writer.Write(143, style.BreakGapSize, map);
25✔
336
                        this._writer.Write(271, (short)style.TextAttachmentDirection, map);
25✔
337
                        this._writer.Write(272, (short)style.TextBottomAttachment, map);
25✔
338
                        this._writer.Write(273, (short)style.TextTopAttachment, map);
25✔
339
                        this._writer.Write(298, false); //        undocumented
25✔
340
                }
25✔
341

342
                private void writeSortentsTable(SortEntitiesTable e)
343
                {
24✔
344
                        this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.SortentsTable);
24✔
345

346
                        this._writer.WriteHandle(330, e.BlockOwner);
24✔
347

348
                        foreach (SortEntitiesTable.Sorter item in e.Sorters)
360✔
349
                        {
144✔
350
                                this._writer.WriteHandle(331, item.Entity);
144✔
351
                                this._writer.Write(5, item.Handle);
144✔
352
                        }
144✔
353
                }
24✔
354

355
                protected void writeXRecord(XRecord e)
356
                {
×
357
                        this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.XRecord);
×
358

359
                        foreach (var item in e.Entries)
×
360
                        {
×
361
                                this._writer.Write(item.Code, item.Value);
×
362
                        }
×
363
                }
×
364
        }
365
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc