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

DomCR / ACadSharp / 30613400426

31 Jul 2026 07:36AM UTC coverage: 75.789% (-0.02%) from 75.805%
30613400426

push

github

web-flow
Merge pull request #1164 from simonedd/add-arc-dimension-entity

Add DimensionArc entity with DWG and DXF read/write support

9191 of 13117 branches covered (70.07%)

Branch coverage included in aggregate %.

68 of 112 new or added lines in 6 files covered. (60.71%)

32997 of 42548 relevant lines covered (77.55%)

152286.8 hits per line

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

87.43
/src/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs
1
using ACadSharp.Entities;
2
using ACadSharp.Entities.AecObjects;
3
using ACadSharp.Entities.Mechanical;
4
using ACadSharp.Objects;
5
using CSMath;
6
using System;
7
using System.Linq;
8

9
namespace ACadSharp.IO.DXF;
10

11
internal abstract partial class DxfSectionWriterBase
12
{
13
        protected void writeEntity<T>(T entity)
14
                where T : Entity
15
        {
12,303✔
16
                if (!this.isEntitySupported(entity))
12,303✔
17
                {
126✔
18
                        return;
126✔
19
                }
20

21
                this._writer.Write(DxfCode.Start, entity.ObjectName);
12,177✔
22

23
                this.writeCommonObjectData(entity);
12,177✔
24

25
                this.writeCommonEntityData(entity);
12,177✔
26

27
                switch (entity)
12,177!
28
                {
29
                        case Arc arc:
30
                                this.writeArc(arc);
120✔
31
                                break;
120✔
32
                        case Circle circle:
33
                                this.writeCircle(circle);
937✔
34
                                break;
937✔
35
                        case Dimension dimension:
36
                                this.writeDimension(dimension);
370✔
37
                                break;
370✔
38
                        case Ellipse ellipse:
39
                                this.writeEllipse(ellipse);
50✔
40
                                break;
50✔
41
                        case Face3D face3D:
42
                                this.writeFace3D(face3D);
20✔
43
                                break;
20✔
44
                        case Hatch hatch:
45
                                this.writeHatch(hatch);
208✔
46
                                break;
208✔
47
                        case Insert insert:
48
                                this.writeInsert(insert);
328✔
49
                                break;
328✔
50
                        case Leader leader:
51
                                this.writeLeader(leader);
26✔
52
                                break;
26✔
53
                        case Line line:
54
                                this.writeLine(line);
2,461✔
55
                                break;
2,461✔
56
                        case LwPolyline lwPolyline:
57
                                this.writeLwPolyline(lwPolyline);
490✔
58
                                break;
490✔
59
                        case Mesh mesh:
60
                                this.writeMesh(mesh);
58✔
61
                                break;
58✔
62
                        case MLine mline:
63
                                this.writeMLine(mline);
66✔
64
                                break;
66✔
65
                        case MText mtext:
66
                                this.writeMText(mtext);
834✔
67
                                break;
834✔
68
                        case MultiLeader multiLeader:
69
                                this.writeMultiLeader(multiLeader);
306✔
70
                                break;
306✔
71
                        case Ole2Frame ole2Frame:
72
                                this.writeOle2Frame(ole2Frame);
×
73
                                break;
×
74
                        case PdfUnderlay pdfUnderlay:
75
                                this.writePdfUnderlay<PdfUnderlay, PdfUnderlayDefinition>(pdfUnderlay);
32✔
76
                                break;
32✔
77
                        case Point point:
78
                                this.writePoint(point);
1,010✔
79
                                break;
1,010✔
80
                        case IPolyline polyline:
81
                                switch (polyline)
160!
82
                                {
83
                                        case Polyline2D polyline2D:
84
                                                this.writePolyline(polyline2D);
36✔
85
                                                break;
36✔
86
                                        case Polyline3D polyline3D:
87
                                                this.writePolyline(polyline3D);
104✔
88
                                                break;
104✔
89
                                        case PolyfaceMesh polyfaceMesh:
90
                                                this.writePolyline(polyfaceMesh);
20✔
91
                                                break;
20✔
92
                                        case PolygonMesh polygonMesh:
93
                                                this.writePolyline(polygonMesh);
×
94
                                                break;
×
95
                                        default:
96
                                                throw new NotImplementedException($"Polyline not implemented {polyline.GetType().FullName}");
×
97
                                }
98
                                break;
160✔
99
                        case RasterImage rasterImage:
100
                                this.writeCadImage(rasterImage);
26✔
101
                                break;
26✔
102
                        case Ray ray:
103
                                this.writeRay(ray);
20✔
104
                                break;
20✔
105
                        case Shape shape:
106
                                this.writeShape(shape);
×
107
                                break;
×
108
                        case Solid solid:
109
                                this.writeSolid(solid);
376✔
110
                                break;
376✔
111
                        case Spline spline:
112
                                this.writeSpline(spline);
52✔
113
                                break;
52✔
114
                        case TextEntity text:
115
                                this.writeTextEntity(text);
868✔
116
                                break;
868✔
117
                        case Tolerance tolerance:
118
                                this.writeTolerance(tolerance);
60✔
119
                                break;
60✔
120
                        case Vertex vertex:
121
                                this.writeVertex(vertex);
2,682✔
122
                                break;
2,682✔
123
                        case Viewport viewport:
124
                                this.writeViewport(viewport);
571✔
125
                                break;
571✔
126
                        case Wipeout wipeout:
127
                                this.writeCadImage(wipeout);
26✔
128
                                break;
26✔
129
                        case XLine xline:
130
                                this.writeXLine(xline);
20✔
131
                                break;
20✔
132
                        default:
133
                                throw new NotImplementedException($"Entity not implemented {entity.GetType().FullName}");
×
134
                }
135

136
                this.writeExtendedData(entity.ExtendedData);
12,177✔
137
        }
12,303✔
138

139
        private bool isEntitySupported(Entity entity)
140
        {
12,303✔
141
                switch (entity)
12,303!
142
                {
143
                        case Seqend://Manually assign at the end of the collections
144
                        case UnknownEntity:
145
                        case MechanicalEntity:
146
                        case Wall:
147
                                return false;
×
148
                        case Shape:
149
                                return this.Configuration.WriteShapes;
20✔
150
                        case ProxyEntity:
151
                        case TableEntity:
152
                        case Solid3D:
153
                        case CadBody:
154
                        case Region:
155
                                this.notify($"Entity type not implemented {entity.GetType().FullName}", NotificationType.NotImplemented);
106✔
156
                                return false;
106✔
157
                        default:
158
                                return true;
12,177✔
159
                }
160
        }
12,303✔
161

162
        private void writeArc(Arc arc)
163
        {
120✔
164
                DxfClassMap map = DxfClassMap.Create<Arc>();
120✔
165

166
                this.writeCircle(arc);
120✔
167

168
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Arc);
120✔
169

170
                this._writer.Write(50, arc.StartAngle, map);
120✔
171
                this._writer.Write(51, arc.EndAngle, map);
120✔
172
        }
120✔
173

174
        private void writeAttributeBase(AttributeBase att)
175
        {
240✔
176
                this._writer.Write(2, att.Tag);
240✔
177

178
                this._writer.Write(70, (short)att.Flags);
240✔
179
                this._writer.Write(73, (short)0);
240✔
180

181
                if (att.VerticalAlignment != 0)
240✔
182
                {
63✔
183
                        this._writer.Write(74, (short)att.VerticalAlignment);
63✔
184
                }
63✔
185

186
                if (this.Version > ACadVersion.AC1027 && att.AttributeType != AttributeType.SingleLine)
240✔
187
                {
6✔
188
                        this._writer.Write(71, (short)att.AttributeType);
6✔
189
                        this._writer.Write(72, (short)0);
6✔
190
                        this._writer.Write(11, att.AlignmentPoint);
6✔
191

192
                        if (att.MText != null)
6✔
193
                        {
6✔
194
                                this._writer.Write(101, "Embedded Object");
6✔
195
                                this.writeMText(att.MText, false);
6✔
196
                        }
6✔
197
                }
6✔
198
        }
240✔
199

200
        private void writeBoundaryPath(Hatch.BoundaryPath path)
201
        {
220✔
202
                this._writer.Write(92, (int)path.Flags);
220✔
203

204
                if (!path.Flags.HasFlag(BoundaryPathFlags.Polyline))
220✔
205
                {
130✔
206
                        this._writer.Write(93, path.Edges.Count);
130✔
207
                }
130✔
208

209
                foreach (Hatch.BoundaryPath.Edge edge in path.Edges)
1,736✔
210
                {
538✔
211
                        this.writeHatchBoundaryPathEdge(edge);
538✔
212
                }
538✔
213

214
                this._writer.Write(97, path.Entities.Count);
220✔
215
                foreach (Entity entity in path.Entities)
976✔
216
                {
158✔
217
                        this._writer.WriteHandle(330, entity);
158✔
218
                }
158✔
219
        }
220✔
220

221
        private void writeCadImage<T>(T image)
222
                where T : CadWipeoutBase
223
        {
52✔
224
                DxfClassMap map = DxfClassMap.Create<T>();
52✔
225

226
                this._writer.Write(DxfCode.Subclass, image.SubclassMarker);
52✔
227

228
                this._writer.Write(90, image.ClassVersion, map);
52✔
229

230
                this._writer.Write(10, image.InsertPoint, map);
52✔
231
                this._writer.Write(11, image.UVector, map);
52✔
232
                this._writer.Write(12, image.VVector, map);
52✔
233
                this._writer.Write(13, image.Size, map);
52✔
234

235
                this._writer.WriteHandle(340, image.Definition, map);
52✔
236

237
                this._writer.Write(70, (short)image.Flags, map);
52✔
238

239
                this._writer.Write(280, image.ClippingState, map);
52✔
240
                this._writer.Write(281, image.Brightness, map);
52✔
241
                this._writer.Write(282, image.Contrast, map);
52✔
242
                this._writer.Write(283, image.Fade, map);
52✔
243

244
                if (image.DefinitionReactor != null)
52✔
245
                {
26✔
246
                        this._writer.WriteHandle(360, image.DefinitionReactor, map);
26✔
247
                        this.Holder.Objects.Enqueue(image.DefinitionReactor);
26✔
248
                }
26✔
249

250
                this._writer.Write(71, (short)image.ClipType, map);
52✔
251

252
                if (image.ClipType == ClipType.Polygonal)
52✔
253
                {
20✔
254
                        this._writer.Write(91, image.ClipBoundaryVertices.Count + 1, map);
20✔
255
                        foreach (XY bv in image.ClipBoundaryVertices)
232✔
256
                        {
86✔
257
                                this._writer.Write(14, bv, map);
86✔
258
                        }
86✔
259

260
                        this._writer.Write(14, image.ClipBoundaryVertices.First(), map);
20✔
261
                }
20✔
262
                else
263
                {
32✔
264
                        this._writer.Write(91, image.ClipBoundaryVertices.Count, map);
32✔
265
                        foreach (XY bv in image.ClipBoundaryVertices)
272✔
266
                        {
88✔
267
                                this._writer.Write(14, bv, map);
88✔
268
                        }
88✔
269
                }
32✔
270
        }
52✔
271

272
        private void writeCircle(Circle circle)
273
        {
1,057✔
274
                DxfClassMap map = DxfClassMap.Create<Circle>();
1,057✔
275

276
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Circle);
1,057✔
277

278
                this._writer.Write(10, circle.Center, map);
1,057✔
279

280
                this._writer.Write(39, circle.Thickness, map);
1,057✔
281
                this._writer.Write(40, circle.Radius, map);
1,057✔
282

283
                this._writer.Write(210, circle.Normal, map);
1,057✔
284
        }
1,057✔
285

286
        private void writeDimension(Dimension dim)
287
        {
370✔
288
                DxfClassMap map = DxfClassMap.Create<Dimension>();
370✔
289

290
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Dimension);
370✔
291

292
                this._writer.WriteName(2, dim.Block, map);
370✔
293

294
                this._writer.Write(10, dim.DefinitionPoint, map);
370✔
295
                this._writer.Write(11, dim.TextMiddlePoint, map);
370✔
296

297
                this._writer.Write(53, dim.TextRotation, map);
370✔
298
                this._writer.Write(70, (short)dim.Flags, map);
370✔
299
                this._writer.Write(71, (short)dim.AttachmentPoint, map);
370✔
300
                this._writer.Write(72, (short)dim.LineSpacingStyle, map);
370✔
301
                this._writer.Write(41, dim.LineSpacingFactor, map);
370✔
302

303
                if (!string.IsNullOrEmpty(dim.Text))
370✔
304
                {
6✔
305
                        this._writer.Write(1, dim.Text, map);
6✔
306
                }
6✔
307

308
                this._writer.Write(210, dim.Normal, map);
370✔
309

310
                this._writer.WriteName(3, dim.Style, map);
370✔
311

312
                switch (dim)
370!
313
                {
314
                        case DimensionAligned aligned:
315
                                this.writeDimensionAligned(aligned);
214✔
316
                                break;
214✔
317
                        case DimensionRadius radius:
318
                                this.writeDimensionRadius(radius);
26✔
319
                                break;
26✔
320
                        case DimensionDiameter diameter:
321
                                this.writeDimensionDiameter(diameter);
32✔
322
                                break;
32✔
323
                        case DimensionAngular2Line angular2Line:
324
                                this.writeDimensionAngular2Line(angular2Line);
26✔
325
                                break;
26✔
326
                        case DimensionAngular3Pt angular3Pt:
327
                                this.writeDimensionAngular3Pt(angular3Pt);
20✔
328
                                break;
20✔
329
                        case DimensionArc arc:
330
                                this.writeDimensionArc(arc);
6✔
331
                                break;
6✔
332
                        case DimensionOrdinate ordinate:
333
                                this.writeDimensionOrdinate(ordinate);
46✔
334
                                break;
46✔
335
                        default:
336
                                throw new NotImplementedException($"Dimension type not implemented {dim.GetType().FullName}");
×
337
                }
338
        }
370✔
339

340
        private void writeDimensionAligned(DimensionAligned aligned)
341
        {
214✔
342
                DxfClassMap map = DxfClassMap.Create<DimensionAligned>();
214✔
343

344
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.AlignedDimension);
214✔
345

346
                this._writer.Write(13, aligned.FirstPoint, map);
214✔
347
                this._writer.Write(14, aligned.SecondPoint, map);
214✔
348

349
                if (aligned is DimensionLinear linear)
214✔
350
                {
138✔
351
                        this.writeDimensionLinear(linear);
138✔
352
                }
138✔
353
        }
214✔
354

355
        private void writeDimensionAngular2Line(DimensionAngular2Line angular2Line)
356
        {
26✔
357
                DxfClassMap map = DxfClassMap.Create<DimensionAngular2Line>();
26✔
358

359
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Angular2LineDimension);
26✔
360

361
                this._writer.Write(13, angular2Line.FirstPoint, map);
26✔
362
                this._writer.Write(14, angular2Line.SecondPoint, map);
26✔
363
                this._writer.Write(15, angular2Line.AngleVertex, map);
26✔
364
                this._writer.Write(16, angular2Line.DimensionArc, map);
26✔
365
        }
26✔
366

367
        private void writeDimensionAngular3Pt(DimensionAngular3Pt angular3Pt)
368
        {
20✔
369
                DxfClassMap map = DxfClassMap.Create<DimensionAngular3Pt>();
20✔
370

371
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Angular3PointDimension);
20✔
372

373
                this._writer.Write(13, angular3Pt.FirstPoint, map);
20✔
374
                this._writer.Write(14, angular3Pt.SecondPoint, map);
20✔
375
                this._writer.Write(15, angular3Pt.AngleVertex, map);
20✔
376
        }
20✔
377

378
        private void writeDimensionArc(DimensionArc arc)
379
        {
6✔
380
                DxfClassMap map = DxfClassMap.Create<DimensionArc>();
6✔
381

382
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.ArcDimension);
6✔
383

384
                this._writer.Write(13, arc.FirstPoint, map);
6✔
385
                this._writer.Write(14, arc.SecondPoint, map);
6✔
386
                this._writer.Write(15, arc.Center, map);
6✔
387
                this._writer.Write(70, (short)(arc.IsPartial ? 1 : 0), map);
6!
388
                this._writer.Write(40, arc.StartAngle, map);
6✔
389
                this._writer.Write(41, arc.EndAngle, map);
6✔
390
                this._writer.Write(71, (short)(arc.HasLeader ? 1 : 0), map);
6!
391

392
                if (arc.HasLeader)
6!
NEW
393
                {
×
NEW
394
                        this._writer.Write(16, arc.LeaderPoint1, map);
×
NEW
395
                        this._writer.Write(17, arc.LeaderPoint2, map);
×
NEW
396
                }
×
397
        }
6✔
398

399
        private void writeDimensionDiameter(DimensionDiameter diameter)
400
        {
32✔
401
                DxfClassMap map = DxfClassMap.Create<DimensionDiameter>();
32✔
402

403
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.DiametricDimension);
32✔
404

405
                this._writer.Write(15, diameter.AngleVertex, map);
32✔
406

407
                this._writer.Write(40, diameter.LeaderLength, map);
32✔
408
        }
32✔
409

410
        private void writeDimensionLinear(DimensionLinear linear)
411
        {
138✔
412
                DxfClassMap map = DxfClassMap.Create<DimensionLinear>();
138✔
413

414
                this._writer.Write(50, linear.Rotation, map);
138✔
415

416
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.LinearDimension);
138✔
417
        }
138✔
418

419
        private void writeDimensionOrdinate(DimensionOrdinate ordinate)
420
        {
46✔
421
                DxfClassMap map = DxfClassMap.Create<DimensionOrdinate>();
46✔
422

423
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.OrdinateDimension);
46✔
424

425
                this._writer.Write(13, ordinate.FeatureLocation, map);
46✔
426
                this._writer.Write(14, ordinate.LeaderEndpoint, map);
46✔
427
        }
46✔
428

429
        private void writeDimensionRadius(DimensionRadius radius)
430
        {
26✔
431
                DxfClassMap map = DxfClassMap.Create<DimensionRadius>();
26✔
432

433
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.RadialDimension);
26✔
434

435
                this._writer.Write(15, radius.AngleVertex, map);
26✔
436

437
                this._writer.Write(40, radius.LeaderLength, map);
26✔
438
        }
26✔
439

440
        private void writeEllipse(Ellipse ellipse)
441
        {
50✔
442
                DxfClassMap map = DxfClassMap.Create<Ellipse>();
50✔
443

444
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Ellipse);
50✔
445

446
                this._writer.Write(10, ellipse.Center, map);
50✔
447

448
                this._writer.Write(11, ellipse.MajorAxisEndPoint, map);
50✔
449

450
                this._writer.Write(210, ellipse.Normal, map);
50✔
451

452
                this._writer.Write(39, ellipse.Thickness, map);
50✔
453
                this._writer.Write(40, ellipse.RadiusRatio, map);
50✔
454
                this._writer.Write(41, ellipse.StartParameter, map);
50✔
455
                this._writer.Write(42, ellipse.EndParameter, map);
50✔
456
        }
50✔
457

458
        private void writeFace3D(Face3D face)
459
        {
20✔
460
                DxfClassMap map = DxfClassMap.Create<Face3D>();
20✔
461

462
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Face3d);
20✔
463

464
                this._writer.Write(10, face.FirstCorner, map);
20✔
465
                this._writer.Write(11, face.SecondCorner, map);
20✔
466
                this._writer.Write(12, face.ThirdCorner, map);
20✔
467
                this._writer.Write(13, face.FourthCorner, map);
20✔
468

469
                this._writer.Write(70, (short)face.Flags, map);
20✔
470
        }
20✔
471

472
        private void writeHatch(Hatch hatch)
473
        {
208✔
474
                DxfClassMap map = DxfClassMap.Create<Hatch>();
208✔
475

476
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Hatch);
208✔
477

478
                this._writer.Write(10, 0, map);
208✔
479
                this._writer.Write(20, 0, map);
208✔
480
                this._writer.Write(30, hatch.Elevation, map);
208✔
481

482
                this._writer.Write(210, hatch.Normal, map);
208✔
483

484
                this._writer.Write(2, hatch.Pattern.Name, map);
208✔
485

486
                this._writer.Write(70, hatch.IsSolid ? (short)1 : (short)0, map);
208✔
487
                this._writer.Write(71, hatch.IsAssociative ? (short)1 : (short)0, map);
208✔
488

489
                this._writer.Write(91, hatch.Paths.Count, map);
208✔
490
                foreach (var path in hatch.Paths)
1,064✔
491
                {
220✔
492
                        this.writeBoundaryPath(path);
220✔
493
                }
220✔
494

495
                this.writeHatchPattern(hatch, hatch.Pattern);
208✔
496

497
                if (!hatch.IsSolid || hatch.Paths.Any(p => p.Flags.HasFlag(BoundaryPathFlags.Derived)) || hatch.PixelSize != 0)
308✔
498
                {
138✔
499
                        this._writer.Write(47, hatch.PixelSize, map);
138✔
500
                }
138✔
501

502
                this._writer.Write(98, hatch.SeedPoints.Count);
208✔
503
                foreach (XY spoint in hatch.SeedPoints)
1,076✔
504
                {
226✔
505
                        this._writer.Write(10, spoint);
226✔
506
                }
226✔
507

508
                //TODO: Implement HatchGradientPattern
509
        }
208✔
510

511
        private void writeHatchBoundaryPathEdge(Hatch.BoundaryPath.Edge edge)
512
        {
538✔
513
                if (edge is not Hatch.BoundaryPath.Polyline)
538✔
514
                {
448✔
515
                        this._writer.Write(72, edge.Type);
448✔
516
                }
448✔
517

518
                switch (edge)
538!
519
                {
520
                        case Hatch.BoundaryPath.Arc arc:
521
                                this._writer.Write(10, arc.Center);
18✔
522
                                this._writer.Write(40, arc.Radius);
18✔
523
                                this._writer.Write(50, MathHelper.RadToDeg(arc.StartAngle));
18✔
524
                                this._writer.Write(51, MathHelper.RadToDeg(arc.EndAngle));
18✔
525
                                this._writer.Write(73, arc.CounterClockWise ? (short)1 : (short)0);
18!
526
                                break;
18✔
527
                        case Hatch.BoundaryPath.Ellipse ellipse:
528
                                this._writer.Write(10, ellipse.Center);
×
529
                                this._writer.Write(11, ellipse.MajorAxisEndPoint);
×
530
                                this._writer.Write(40, ellipse.RadiusRatio);
×
531
                                this._writer.Write(50, MathHelper.RadToDeg(ellipse.StartAngle));
×
532
                                this._writer.Write(51, MathHelper.RadToDeg(ellipse.EndAngle));
×
533
                                this._writer.Write(73, ellipse.CounterClockWise ? (short)1 : (short)0);
×
534
                                break;
×
535
                        case Hatch.BoundaryPath.Line line:
536
                                this._writer.Write(10, line.Start);
430✔
537
                                this._writer.Write(11, line.End);
430✔
538
                                break;
430✔
539
                        case Hatch.BoundaryPath.Polyline poly:
540
                                this._writer.Write(72, poly.HasBulge ? (short)1 : (short)0);
90✔
541
                                this._writer.Write(73, poly.IsClosed ? (short)1 : (short)0);
90✔
542
                                this._writer.Write(93, poly.Vertices.Count);
90✔
543
                                for (int i = 0; i < poly.Vertices.Count; i++)
900✔
544
                                {
360✔
545
                                        this._writer.Write(10, (XY)poly.Vertices[i]);
360✔
546
                                        if (poly.HasBulge)
360✔
547
                                        {
12✔
548
                                                this._writer.Write(42, poly.Bulges.ElementAtOrDefault(i));
12✔
549
                                        }
12✔
550
                                }
360✔
551
                                break;
90✔
552
                        case Hatch.BoundaryPath.Spline spline:
553
                                this._writer.Write(94, (int)spline.Degree);
×
554
                                this._writer.Write(73, spline.IsRational ? (short)1 : (short)0);
×
555
                                this._writer.Write(74, spline.IsPeriodic ? (short)1 : (short)0);
×
556

557
                                this._writer.Write(95, spline.Knots.Count);
×
558
                                this._writer.Write(96, spline.ControlPoints.Count);
×
559

560
                                foreach (double knot in spline.Knots)
×
561
                                {
×
562
                                        this._writer.Write(40, knot);
×
563
                                }
×
564

565
                                foreach (var point in spline.ControlPoints)
×
566
                                {
×
567
                                        this._writer.Write(10, point.X);
×
568
                                        this._writer.Write(20, point.Y);
×
569
                                        if (spline.IsRational)
×
570
                                        {
×
571
                                                this._writer.Write(42, point.Z);
×
572
                                        }
×
573
                                }
×
574

575
                                this._writer.Write(97, spline.FitPoints.Count);
×
576
                                foreach (var fitPoint in spline.FitPoints)
×
577
                                {
×
578
                                        this._writer.Write(11, fitPoint.X);
×
579
                                        this._writer.Write(21, fitPoint.Y);
×
580
                                }
×
581

582
                                if (spline.FitPoints.Count > 0)
×
583
                                {
×
584
                                        this._writer.Write(12, spline.StartTangent.X);
×
585
                                        this._writer.Write(22, spline.StartTangent.Y);
×
586
                                        this._writer.Write(13, spline.EndTangent.X);
×
587
                                        this._writer.Write(23, spline.EndTangent.Y);
×
588
                                }
×
589
                                break;
×
590
                        default:
591
                                throw new ArgumentException($"Unknown Hatch.BoundaryPath.Edge type {edge.GetType().FullName}");
×
592
                }
593
        }
538✔
594

595
        private void writeHatchPattern(Hatch hatch, HatchPattern pattern)
596
        {
208✔
597
                this._writer.Write(75, (short)hatch.Style);
208✔
598
                this._writer.Write(76, (short)hatch.PatternType);
208✔
599

600
                if (!hatch.IsSolid)
208✔
601
                {
120✔
602
                        this._writer.Write(52, MathHelper.RadToDeg(hatch.PatternAngle));
120✔
603
                        this._writer.Write(41, hatch.PatternScale);
120✔
604
                        this._writer.Write(77, (short)(hatch.IsDouble ? 1 : 0));
120!
605
                        this._writer.Write(78, (short)pattern.Lines.Count);
120✔
606
                        foreach (HatchPattern.Line line in pattern.Lines)
18,320✔
607
                        {
8,980✔
608
                                this._writer.Write(53, MathHelper.RadToDeg(line.Angle));
8,980✔
609
                                this._writer.Write(43, line.BasePoint.X);
8,980✔
610
                                this._writer.Write(44, line.BasePoint.Y);
8,980✔
611
                                this._writer.Write(45, line.Offset.X);
8,980✔
612
                                this._writer.Write(46, line.Offset.Y);
8,980✔
613
                                this._writer.Write(79, (short)line.DashLengths.Count);
8,980✔
614
                                foreach (double dashLength in line.DashLengths)
62,780✔
615
                                {
17,920✔
616
                                        this._writer.Write(49, dashLength);
17,920✔
617
                                }
17,920✔
618
                        }
8,980✔
619
                }
120✔
620
        }
208✔
621

622
        private void writeInsert(Insert insert)
623
        {
328✔
624
                DxfClassMap map = DxfClassMap.Create<Insert>();
328✔
625

626
                this._writer.Write(DxfCode.Subclass, insert.SubclassMarker);
328✔
627

628
                this._writer.WriteName(2, insert.Block, map);
328✔
629

630
                this._writer.Write(10, insert.InsertPoint, map);
328✔
631

632
                this._writer.Write(41, insert.XScale, map);
328✔
633
                this._writer.Write(42, insert.YScale, map);
328✔
634
                this._writer.Write(43, insert.ZScale, map);
328✔
635

636
                this._writer.Write(50, insert.Rotation, map);
328✔
637

638
                this._writer.Write(70, (short)insert.ColumnCount);
328✔
639
                this._writer.Write(71, (short)insert.RowCount);
328✔
640

641
                this._writer.Write(44, insert.ColumnSpacing);
328✔
642
                this._writer.Write(45, insert.RowSpacing);
328✔
643

644
                this._writer.Write(210, insert.Normal, map);
328✔
645

646
                if (insert.HasAttributes)
328✔
647
                {
52✔
648
                        this._writer.Write(66, 1);
52✔
649

650
                        //WARNING: Write extended data before attributes
651

652
                        foreach (var att in insert.Attributes)
388✔
653
                        {
116✔
654
                                this.writeEntity(att);
116✔
655
                        }
116✔
656

657
                        this.writeSeqend(insert.Attributes.Seqend);
52✔
658
                }
52✔
659
        }
328✔
660

661
        private void writeLeader(Leader leader)
662
        {
26✔
663
                DxfClassMap map = DxfClassMap.Create<Leader>();
26✔
664

665
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Leader);
26✔
666

667
                this._writer.WriteName(3, leader.Style, map);
26✔
668

669
                this._writer.Write(71, leader.ArrowHeadEnabled ? (short)1 : (short)0, map);
26✔
670
                this._writer.Write(72, (short)leader.PathType, map);
26✔
671
                this._writer.Write(73, (short)leader.CreationType, map);
26✔
672
                this._writer.Write(74, leader.HookLineDirection == HookLineDirection.Same ? (short)1 : (short)0, map);
26!
673
                this._writer.Write(75, leader.HasHookline ? (short)1 : (short)0, map);
26!
674

675
                this._writer.Write(40, leader.TextHeight, map);
26✔
676
                this._writer.Write(41, leader.TextWidth, map);
26✔
677

678
                this._writer.Write(76, leader.Vertices.Count, map);
26✔
679
                foreach (var vertex in leader.Vertices)
234✔
680
                {
78✔
681
                        this._writer.Write(10, vertex, map);
78✔
682
                }
78✔
683

684
                //this._writer.Write(77, leader,map);
685
                //this._writer.Write(340, leader.Annotation,map);
686

687
                this._writer.Write(210, leader.Normal, map);
26✔
688

689
                this._writer.Write(211, leader.HorizontalDirection, map);
26✔
690
                this._writer.Write(212, leader.BlockOffset, map);
26✔
691
                this._writer.Write(213, leader.AnnotationOffset, map);
26✔
692
        }
26✔
693

694
        private void writeLeaderLine(MultiLeaderObjectContextData.LeaderLine leaderLine)
695
        {
306✔
696
                this._writer.Write(304, "LEADER_LINE{");
306✔
697

698
                foreach (XYZ point in leaderLine.Points)
1,530✔
699
                {
306✔
700
                        this._writer.Write(10, point);
306✔
701
                }
306✔
702
                this._writer.Write(91, leaderLine.Index);
306✔
703

704
                this._writer.Write(305, "}");   //        LEADER_Line
306✔
705
        }
306✔
706

707
        private void writeLeaderRoot(MultiLeaderObjectContextData.LeaderRoot leaderRoot)
708
        {
306✔
709
                this._writer.Write(302, "LEADER{");
306✔
710

711
                // TODO: true is placeholder
712
                this._writer.Write(290, true ? (short)1 : (short)0); // Has Set Last Leader Line Point
306✔
713
                this._writer.Write(291, true ? (short)1 : (short)0); // Has Set Dogleg Vector
306✔
714

715
                this._writer.Write(10, leaderRoot.ConnectionPoint);
306✔
716

717
                this._writer.Write(11, leaderRoot.Direction);
306✔
718

719
                this._writer.Write(90, leaderRoot.LeaderIndex);
306✔
720
                this._writer.Write(40, leaderRoot.LandingDistance);
306✔
721

722
                foreach (MultiLeaderObjectContextData.LeaderLine leaderLine in leaderRoot.Lines)
1,530✔
723
                {
306✔
724
                        writeLeaderLine(leaderLine);
306✔
725
                }
306✔
726

727
                this._writer.Write(271, 0);
306✔
728
                this._writer.Write(303, "}");   //        LEADER
306✔
729
        }
306✔
730

731
        private void writeLine(Line line)
732
        {
2,461✔
733
                DxfClassMap map = DxfClassMap.Create<Line>();
2,461✔
734

735
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Line);
2,461✔
736

737
                this._writer.Write(10, line.StartPoint, map);
2,461✔
738

739
                this._writer.Write(11, line.EndPoint, map);
2,461✔
740

741
                this._writer.Write(39, line.Thickness, map);
2,461✔
742

743
                this._writer.Write(210, line.Normal, map);
2,461✔
744
        }
2,461✔
745

746
        private void writeLwPolyline(LwPolyline polyline)
747
        {
490✔
748
                DxfClassMap map = DxfClassMap.Create<LwPolyline>();
490✔
749

750
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.LwPolyline);
490✔
751

752
                this._writer.Write(90, polyline.Vertices.Count);
490✔
753
                this._writer.Write(70, (short)polyline.Flags);
490✔
754

755
                if (polyline.ConstantWidth != 0.0)
490✔
756
                {
44✔
757
                        this._writer.Write(43, polyline.ConstantWidth);
44✔
758
                }
44✔
759

760
                this._writer.Write(38, polyline.Elevation);
490✔
761
                this._writer.Write(39, polyline.Thickness);
490✔
762

763
                foreach (LwPolyline.Vertex v in polyline.Vertices)
5,682✔
764
                {
2,106✔
765
                        this._writer.Write(10, v.Location);
2,106✔
766
                        this._writer.Write(40, v.StartWidth);
2,106✔
767
                        this._writer.Write(41, v.EndWidth);
2,106✔
768
                        this._writer.Write(42, v.Bulge);
2,106✔
769
                }
2,106✔
770

771
                this._writer.Write(210, polyline.Normal, map);
490✔
772
        }
490✔
773

774
        private void writeMesh(Mesh mesh)
775
        {
58✔
776
                DxfClassMap map = DxfClassMap.Create<Mesh>();
58✔
777

778
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Mesh);
58✔
779

780
                this._writer.Write(71, (short)mesh.Version, map);
58✔
781
                this._writer.Write(72, (short)(mesh.BlendCrease ? 1 : 0), map);
58!
782

783
                this._writer.Write(91, mesh.SubdivisionLevel, map);
58✔
784

785
                this._writer.Write(92, mesh.Vertices.Count, map);
58✔
786
                foreach (XYZ vertex in mesh.Vertices)
5,370✔
787
                {
2,598✔
788
                        this._writer.Write(10, vertex, map);
2,598✔
789
                }
2,598✔
790

791
                int nFaces = mesh.Faces.Count;
58✔
792
                nFaces += mesh.Faces.Sum(f => f.Length);
2,802✔
793

794
                this._writer.Write(93, nFaces);
58✔
795
                foreach (int[] face in mesh.Faces)
5,662✔
796
                {
2,744✔
797
                        this._writer.Write(90, face.Length);
2,744✔
798
                        foreach (int index in face)
29,188✔
799
                        {
10,478✔
800
                                this._writer.Write(90, index);
10,478✔
801
                        }
10,478✔
802
                }
2,744✔
803

804
                this._writer.Write(94, mesh.Edges.Count, map);
58✔
805
                foreach (Mesh.Edge edge in mesh.Edges)
10,574✔
806
                {
5,200✔
807
                        this._writer.Write(90, edge.Start);
5,200✔
808
                        this._writer.Write(90, edge.End);
5,200✔
809
                }
5,200✔
810

811
                this._writer.Write(95, mesh.Edges.Count, map);
58✔
812
                foreach (Mesh.Edge edge in mesh.Edges)
10,574✔
813
                {
5,200✔
814
                        this._writer.Write(140, edge.Crease.HasValue ? edge.Crease.Value : 0.0d);
5,200!
815
                }
5,200✔
816

817
                this._writer.Write(90, 0);
58✔
818
        }
58✔
819

820
        private void writeMLine(MLine mLine)
821
        {
66✔
822
                DxfClassMap map = DxfClassMap.Create<MLine>();
66✔
823

824
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.MLine);
66✔
825

826
                //Style has two references
827
                this._writer.WriteName(2, mLine.Style, map);
66✔
828
                this._writer.WriteHandle(340, mLine.Style, map);
66✔
829

830
                this._writer.Write(40, mLine.ScaleFactor);
66✔
831

832
                this._writer.Write(70, (short)mLine.Justification);
66✔
833
                this._writer.Write(71, (short)mLine.Flags);
66✔
834
                this._writer.Write(72, (short)mLine.Vertices.Count);
66✔
835

836
                if (mLine.Style != null)
66✔
837
                {
66✔
838
                        this._writer.Write(73, (short)mLine.Style.Elements.Count());
66✔
839
                }
66✔
840

841
                this._writer.Write(10, mLine.StartPoint, map);
66✔
842

843
                this._writer.Write(210, mLine.Normal);
66✔
844

845
                foreach (var v in mLine.Vertices)
702✔
846
                {
252✔
847
                        this._writer.Write(11, v.Position, map);
252✔
848
                        this._writer.Write(12, v.Direction, map);
252✔
849
                        this._writer.Write(13, v.Miter, map);
252✔
850

851
                        foreach (var s in v.Segments)
1,764✔
852
                        {
504✔
853
                                this._writer.Write(74, (short)s.Parameters.Count);
504✔
854
                                foreach (double parameter in s.Parameters)
3,608✔
855
                                {
1,048✔
856
                                        this._writer.Write(41, parameter);
1,048✔
857
                                }
1,048✔
858
                                this._writer.Write(75, (short)s.AreaFillParameters.Count);
504✔
859
                                foreach (double areaFillParameter in s.AreaFillParameters)
1,512!
860
                                {
×
861
                                        this._writer.Write(42, areaFillParameter);
×
862
                                }
×
863
                        }
504✔
864
                }
252✔
865
        }
66✔
866

867
        private void writeMText(MText mtext, bool writeSubclass = true)
868
        {
840✔
869
                DxfClassMap map = DxfClassMap.Create<MText>();
840✔
870

871
                if (writeSubclass)
840✔
872
                {
834✔
873
                        this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.MText);
834✔
874
                }
834✔
875

876
                this._writer.Write(10, mtext.InsertPoint, map);
840✔
877

878
                this._writer.Write(40, mtext.Height, map);
840✔
879
                this._writer.Write(41, mtext.RectangleWidth, map);
840✔
880
                this._writer.Write(44, mtext.LineSpacing, map);
840✔
881

882
                if (this.Version >= ACadVersion.AC1021)
840✔
883
                {
514✔
884
                        this._writer.Write(46, mtext.RectangleHeight, map);
514✔
885
                }
514✔
886

887
                this._writer.Write(71, (short)mtext.AttachmentPoint, map);
840✔
888
                this._writer.Write(72, (short)mtext.DrawingDirection, map);
840✔
889

890
                this.writeLongTextValue(1, 3, mtext.Value);
840✔
891

892
                this._writer.WriteName(7, mtext.Style);
840✔
893

894
                this._writer.Write(73, (short)mtext.LineSpacingStyle, map);
840✔
895

896
                this._writer.Write(11, mtext.AlignmentPoint, map);
840✔
897

898
                this._writer.Write(210, mtext.Normal, map);
840✔
899

900
                if (!mtext.HasColumns || this.Version < ACadVersion.AC1032)
840✔
901
                {
828✔
902
                        return;
828✔
903
                }
904

905
                this._writer.Write(101, "Embedded Object");
12✔
906
                this._writer.Write(70, (short)1);
12✔
907

908
                this._writer.Write(10, mtext.AlignmentPoint);
12✔
909
                this._writer.Write(11, mtext.InsertPoint);
12✔
910

911
                this._writer.Write(40, mtext.RectangleWidth);
12✔
912
                this._writer.Write(41, mtext.RectangleHeight);
12✔
913
                this._writer.Write(42, mtext.HorizontalWidth);
12✔
914
                this._writer.Write(43, mtext.VerticalHeight);
12✔
915

916
                this._writer.Write(71, (short)mtext.ColumnData.ColumnType);
12✔
917
                this._writer.Write(72, (short)mtext.ColumnData.ColumnCount);
12✔
918
                this._writer.Write(44, mtext.ColumnData.Width);
12✔
919
                this._writer.Write(45, mtext.ColumnData.Gutter);
12✔
920
                this._writer.Write(73, mtext.ColumnData.AutoHeight ? (short)1 : (short)0);
12!
921
                this._writer.Write(74, mtext.ColumnData.FlowReversed ? (short)1 : (short)0);
12!
922

923
                foreach (double h in mtext.ColumnData.Heights)
60✔
924
                {
12✔
925
                        this._writer.Write(46, h);
12✔
926
                }
12✔
927
        }
840✔
928

929
        private void writeMultiLeader(MultiLeader multiLeader)
930
        {
306✔
931
                MultiLeaderObjectContextData contextData = multiLeader.ContextData;
306✔
932

933
                this._writer.Write(100, "AcDbMLeader");
306✔
934

935
                //        version
936
                //        if (Version > ACadVersion.
937
                this._writer.Write(270, 2);
306✔
938

939
                writeMultiLeaderAnnotContext(contextData);
306✔
940

941
                //        MultiLeader properties
942
                this._writer.WriteHandle(340, multiLeader.Style);
306✔
943
                this._writer.Write(90, multiLeader.PropertyOverrideFlags);
306✔
944
                this._writer.Write(170, (short)multiLeader.PathType);
306✔
945

946
                this._writer.WriteCmColor(91, multiLeader.LineColor);
306✔
947

948
                this._writer.WriteHandle(341, multiLeader.LineType);
306✔
949
                this._writer.Write(171, (short)multiLeader.LeaderLineWeight);
306✔
950
                this._writer.Write(290, multiLeader.EnableLanding);
306✔
951
                this._writer.Write(291, multiLeader.EnableDogleg);
306✔
952
                this._writer.Write(41, multiLeader.LandingDistance);
306✔
953
                this._writer.Write(42, multiLeader.ArrowheadSize);
306✔
954
                this._writer.Write(172, (short)multiLeader.ContentType);
306✔
955
                this._writer.WriteHandle(343, multiLeader.TextStyle);
306✔
956
                this._writer.Write(173, (short)multiLeader.TextLeftAttachment);
306✔
957
                this._writer.Write(95, (short)multiLeader.TextRightAttachment);
306✔
958
                this._writer.Write(174, (short)multiLeader.TextAngle);
306✔
959
                this._writer.Write(175, (short)multiLeader.TextAlignment);
306✔
960

961
                this._writer.WriteCmColor(92, multiLeader.TextColor);
306✔
962

963
                this._writer.Write(292, multiLeader.TextFrame);
306✔
964

965
                this._writer.WriteCmColor(93, multiLeader.BlockContentColor);
306✔
966

967
                this._writer.Write(10, multiLeader.BlockContentScale);
306✔
968

969
                this._writer.Write(43, multiLeader.BlockContentRotation);
306✔
970
                this._writer.Write(176, (short)multiLeader.BlockContentConnection);
306✔
971
                this._writer.Write(293, multiLeader.EnableAnnotationScale);
306✔
972
                this._writer.Write(294, multiLeader.TextDirectionNegative);
306✔
973
                this._writer.Write(178, multiLeader.TextAligninIPE);
306✔
974
                this._writer.Write(179, multiLeader.TextAttachmentPoint);
306✔
975
                this._writer.Write(45, multiLeader.ScaleFactor);
306✔
976
                this._writer.Write(271, multiLeader.TextAttachmentDirection);
306✔
977
                this._writer.Write(272, multiLeader.TextBottomAttachment);
306✔
978
                this._writer.Write(273, multiLeader.TextTopAttachment);
306✔
979
                this._writer.Write(295, 0);
306✔
980
        }
306✔
981

982
        private void writeMultiLeaderAnnotContext(MultiLeaderObjectContextData contextData)
983
        {
306✔
984
                this._writer.Write(300, "CONTEXT_DATA{");
306✔
985
                this._writer.Write(40, contextData.ScaleFactor);
306✔
986
                this._writer.Write(10, contextData.ContentBasePoint);
306✔
987
                this._writer.Write(41, contextData.TextHeight);
306✔
988
                this._writer.Write(140, contextData.ArrowheadSize);
306✔
989
                this._writer.Write(145, contextData.LandingGap);
306✔
990
                this._writer.Write(174, (short)contextData.TextLeftAttachment);
306✔
991
                this._writer.Write(175, (short)contextData.TextRightAttachment);
306✔
992
                this._writer.Write(176, (short)contextData.TextAlignment);
306✔
993
                this._writer.Write(177, (short)contextData.BlockContentConnection);
306✔
994
                this._writer.Write(290, contextData.HasTextContents);
306✔
995
                this._writer.Write(304, contextData.TextLabel);
306✔
996

997
                this._writer.Write(11, contextData.TextNormal);
306✔
998

999
                this._writer.WriteHandle(340, contextData.TextStyle);
306✔
1000

1001
                this._writer.Write(12, contextData.TextLocation);
306✔
1002

1003
                this._writer.Write(13, contextData.Direction);
306✔
1004

1005
                this._writer.Write(42, contextData.TextRotation);
306✔
1006
                this._writer.Write(43, contextData.BoundaryWidth);
306✔
1007
                this._writer.Write(44, contextData.BoundaryHeight);
306✔
1008
                this._writer.Write(45, contextData.LineSpacingFactor);
306✔
1009
                this._writer.Write(170, (short)contextData.LineSpacing);
306✔
1010

1011
                this._writer.WriteCmColor(90, contextData.TextColor);
306✔
1012

1013
                this._writer.Write(171, (short)contextData.TextAttachmentPoint);
306✔
1014
                this._writer.Write(172, (short)contextData.FlowDirection);
306✔
1015

1016
                this._writer.WriteCmColor(91, contextData.BackgroundFillColor);
306✔
1017

1018
                this._writer.Write(141, contextData.BackgroundScaleFactor);
306✔
1019
                this._writer.Write(92, contextData.BackgroundTransparency);
306✔
1020
                this._writer.Write(291, contextData.BackgroundFillEnabled);
306✔
1021
                this._writer.Write(292, contextData.BackgroundMaskFillOn);
306✔
1022
                this._writer.Write(173, contextData.ColumnType);
306✔
1023
                this._writer.Write(293, contextData.TextHeightAutomatic);
306✔
1024
                this._writer.Write(142, contextData.ColumnWidth);
306✔
1025
                this._writer.Write(143, contextData.ColumnGutter);
306✔
1026
                this._writer.Write(294, contextData.ColumnFlowReversed);
306✔
1027
                this._writer.Write(295, contextData.WordBreak);
306✔
1028

1029
                this._writer.Write(296, contextData.HasContentsBlock);
306✔
1030

1031
                this._writer.Write(110, contextData.BasePoint);
306✔
1032

1033
                this._writer.Write(111, contextData.BaseDirection);
306✔
1034

1035
                this._writer.Write(112, contextData.BaseVertical);
306✔
1036

1037
                this._writer.Write(297, contextData.NormalReversed);
306✔
1038

1039
                foreach (MultiLeaderObjectContextData.LeaderRoot leaderRoot in contextData.LeaderRoots)
1,530✔
1040
                {
306✔
1041
                        writeLeaderRoot(leaderRoot);
306✔
1042
                }
306✔
1043

1044
                this._writer.Write(272, (short)contextData.TextBottomAttachment);
306✔
1045
                this._writer.Write(273, (short)contextData.TextTopAttachment);
306✔
1046
                this._writer.Write(301, "}");       //        CONTEXT_DATA
306✔
1047
        }
306✔
1048

1049
        private void writePdfUnderlay<T, R>(T underlay)
1050
                where T : UnderlayEntity<R>
1051
                where R : UnderlayDefinition
1052
        {
32✔
1053
                DxfClassMap map = DxfClassMap.Create<T>();
32✔
1054

1055
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Underlay);
32✔
1056

1057
                this._writer.WriteHandle(340, underlay.Definition, map);
32✔
1058

1059
                this._writer.Write(10, underlay.InsertPoint, map);
32✔
1060

1061
                this._writer.Write(280, underlay.Flags, map);
32✔
1062
                this._writer.Write(281, underlay.Contrast, map);
32✔
1063
                this._writer.Write(282, underlay.Fade, map);
32✔
1064

1065
                foreach (XY bv in underlay.ClipBoundaryVertices)
144✔
1066
                {
24✔
1067
                        this._writer.Write(11, bv, map);
24✔
1068
                }
24✔
1069
        }
32✔
1070

1071
        private void writeOle2Frame(Ole2Frame ole)
1072
        {
×
1073
                DxfClassMap map = DxfClassMap.Create<Ole2Frame>();
×
1074

1075
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Ole2Frame);
×
1076

1077
                this._writer.Write(70, ole.Version, map);
×
1078
                this._writer.Write(3, ole.SourceApplication, map);
×
1079

1080
                this._writer.Write(10, ole.UpperLeftCorner, map);
×
1081
                this._writer.Write(11, ole.LowerRightCorner, map);
×
1082

1083
                this._writer.Write(71, ole.OleObjectType, map);
×
1084
                this._writer.Write(72, ole.IsPaperSpace, map);
×
1085
                this._writer.Write(73, 3, map);//Undocumented
×
1086

1087
                this._writer.Write(90, ole.BinaryData.Length, map);
×
1088
                this._writer.Write(310, ole.BinaryData, map);
×
1089
                this._writer.Write(1, "OLE");
×
1090
        }
×
1091

1092
        private void writePoint(Point point)
1093
        {
1,010✔
1094
                DxfClassMap map = DxfClassMap.Create<Point>();
1,010✔
1095

1096
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Point);
1,010✔
1097

1098
                this._writer.Write(10, point.Location, map);
1,010✔
1099

1100
                this._writer.Write(39, point.Thickness, map);
1,010✔
1101

1102
                this._writer.Write(210, point.Normal, map);
1,010✔
1103

1104
                this._writer.Write(50, point.Rotation, map);
1,010✔
1105
        }
1,010✔
1106

1107
        private void writePolyline<T>(Polyline<T> polyline)
1108
                where T : Entity, IVertex
1109
        {
160✔
1110
                DxfClassMap map;
1111

1112
                switch (polyline)
160!
1113
                {
1114
                        case Polyline2D:
1115
                                map = DxfClassMap.Create<Polyline2D>();
36✔
1116
                                break;
36✔
1117
                        case Polyline3D:
1118
                                map = DxfClassMap.Create<Polyline3D>();
104✔
1119
                                break;
104✔
1120
                        case PolyfaceMesh:
1121
                                map = DxfClassMap.Create<PolyfaceMesh>();
20✔
1122
                                break;
20✔
1123
                        case PolygonMesh:
1124
                                map = DxfClassMap.Create<PolygonMesh>();
×
1125
                                break;
×
1126
                        default:
1127
                                throw new NotImplementedException($"Polyline not implemented {polyline.GetType().FullName}");
×
1128
                }
1129

1130
                this._writer.Write(DxfCode.Subclass, polyline.SubclassMarker);
160✔
1131

1132
                this._writer.Write(DxfCode.XCoordinate, 0);
160✔
1133
                this._writer.Write(DxfCode.YCoordinate, 0);
160✔
1134
                this._writer.Write(DxfCode.ZCoordinate, polyline.Elevation);
160✔
1135

1136
                this._writer.Write(70, (short)polyline.Flags, map);
160✔
1137
                this._writer.Write(75, (short)polyline.SmoothSurface, map);
160✔
1138

1139
                if (polyline is PolygonMesh polygon)
160!
1140
                {
×
1141
                        this._writer.WriteIfNotDefault(71, polygon.MVertexCount, 0, map);
×
1142
                        this._writer.WriteIfNotDefault(72, polygon.MVertexCount, 0, map);
×
1143
                        this._writer.WriteIfNotDefault(73, polygon.MSmoothSurfaceDensity, 0, map);
×
1144
                        this._writer.WriteIfNotDefault(74, polygon.NSmoothSurfaceDensity, 0, map);
×
1145
                }
×
1146
                else if (polyline is PolyfaceMesh faceMesh)
160✔
1147
                {
20✔
1148
                        this._writer.WriteIfNotDefault(71, faceMesh.Vertices.Count, 0, map);
20✔
1149
                        this._writer.WriteIfNotDefault(72, faceMesh.Faces.Count, 0, map);
20✔
1150
                }
20✔
1151

1152
                this._writer.Write(210, polyline.Normal, map);
160✔
1153

1154
                if (polyline.Vertices.Any())
160✔
1155
                {
148✔
1156
                        foreach (T v in polyline.Vertices)
5,728✔
1157
                        {
2,642✔
1158
                                this.writeEntity(v);
2,642✔
1159
                        }
2,642✔
1160

1161
                        if (polyline is PolyfaceMesh faceMesh)
148✔
1162
                        {
20✔
1163
                                foreach (var f in faceMesh.Faces)
140✔
1164
                                {
40✔
1165
                                        this.writeEntity(f);
40✔
1166
                                }
40✔
1167
                        }
20✔
1168

1169
                        this.writeSeqend(polyline.Vertices.Seqend);
148✔
1170
                }
148✔
1171
        }
160✔
1172

1173
        private void writeRay(Ray ray)
1174
        {
20✔
1175
                DxfClassMap map = DxfClassMap.Create<Ray>();
20✔
1176

1177
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Ray);
20✔
1178

1179
                this._writer.Write(10, ray.StartPoint, map);
20✔
1180

1181
                this._writer.Write(11, ray.Direction, map);
20✔
1182
        }
20✔
1183

1184
        private void writeSeqend(Seqend seqend)
1185
        {
200✔
1186
                this._writer.Write(0, seqend.ObjectName);
200✔
1187
                this._writer.Write(5, seqend.Handle);
200✔
1188
                this._writer.Write(330, seqend.Owner.Handle);
200✔
1189
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Entity);
200✔
1190
                this._writer.Write(8, seqend.Layer.Name);
200✔
1191
        }
200✔
1192

1193
        private void writeShape(Shape shape)
1194
        {
×
1195
                DxfClassMap map = DxfClassMap.Create<Shape>();
×
1196

1197
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Shape);
×
1198

1199
                this._writer.Write(39, shape.Thickness, map);
×
1200

1201
                this._writer.Write(10, shape.InsertionPoint, map);
×
1202

1203
                this._writer.Write(40, shape.Size, map);
×
1204

1205
                this._writer.WriteName(2, shape.ShapeStyle, map);
×
1206

1207
                this._writer.Write(50, shape.Rotation, map);
×
1208

1209
                this._writer.Write(41, shape.RelativeXScale, map);
×
1210
                this._writer.Write(51, shape.ObliqueAngle, map);
×
1211

1212
                this._writer.Write(210, shape.Normal, map);
×
1213
        }
×
1214

1215
        private void writeSolid(Solid solid)
1216
        {
376✔
1217
                DxfClassMap map = DxfClassMap.Create<Solid>();
376✔
1218

1219
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Solid);
376✔
1220

1221
                this._writer.Write(10, solid.FirstCorner, map);
376✔
1222
                this._writer.Write(11, solid.SecondCorner, map);
376✔
1223
                this._writer.Write(12, solid.ThirdCorner, map);
376✔
1224
                this._writer.Write(13, solid.FourthCorner, map);
376✔
1225

1226
                this._writer.Write(39, solid.Thickness, map);
376✔
1227

1228
                this._writer.Write(210, solid.Normal, map);
376✔
1229
        }
376✔
1230

1231
        private void writeSpline(Spline spline)
1232
        {
52✔
1233
                DxfClassMap map = DxfClassMap.Create<Spline>();
52✔
1234

1235
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Spline);
52✔
1236

1237
                if (spline.Flags.HasFlag(SplineFlags.Planar))
52✔
1238
                {
12✔
1239
                        this._writer.Write(210, spline.Normal, map);
12✔
1240
                }
12✔
1241

1242
                this._writer.Write(70, (short)spline.Flags, map);
52✔
1243
                this._writer.Write(71, (short)spline.Degree, map);
52✔
1244
                this._writer.Write(72, (short)spline.Knots.Count, map);
52✔
1245
                this._writer.Write(73, (short)spline.ControlPoints.Count, map);
52✔
1246

1247
                if (spline.FitPoints.Any())
52✔
1248
                {
10✔
1249
                        this._writer.Write(74, (short)spline.FitPoints.Count, map);
10✔
1250
                }
10✔
1251

1252
                this._writer.Write(42, spline.KnotTolerance, map);
52✔
1253
                this._writer.Write(43, spline.ControlPointTolerance, map);
52✔
1254
                this._writer.Write(44, spline.FitTolerance, map);
52✔
1255

1256
                if (!spline.StartTangent.IsZero())
52✔
1257
                {
4✔
1258
                        this._writer.Write(12, spline.StartTangent, map);
4✔
1259
                }
4✔
1260
                if (!spline.EndTangent.IsZero())
52✔
1261
                {
4✔
1262
                        this._writer.Write(13, spline.EndTangent, map);
4✔
1263
                }
4✔
1264

1265
                foreach (double knot in spline.Knots)
960✔
1266
                {
402✔
1267
                        this._writer.Write(40, knot, map);
402✔
1268
                }
402✔
1269
                foreach (double weight in spline.Weights)
240✔
1270
                {
42✔
1271
                        this._writer.Write(41, weight, map);
42✔
1272
                }
42✔
1273
                foreach (var cp in spline.ControlPoints)
576✔
1274
                {
210✔
1275
                        this._writer.Write(10, cp, map);
210✔
1276
                }
210✔
1277
                foreach (var fp in spline.FitPoints)
232✔
1278
                {
38✔
1279
                        this._writer.Write(11, fp, map);
38✔
1280
                }
38✔
1281
        }
52✔
1282

1283
        private void writeTextEntity(TextEntity text)
1284
        {
868✔
1285
                DxfClassMap map = DxfClassMap.Create<TextEntity>();
868✔
1286

1287
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Text);
868✔
1288

1289
                this._writer.Write(1, text.Value, map);
868✔
1290

1291
                this._writer.Write(10, text.InsertPoint, map);
868✔
1292

1293
                this._writer.Write(40, text.Height, map);
868✔
1294

1295
                if (text.WidthFactor != 1.0)
868!
1296
                {
×
1297
                        this._writer.Write(41, text.WidthFactor, map);
×
1298
                }
×
1299

1300
                if (text.Rotation != 0.0)
868!
1301
                {
×
1302
                        this._writer.Write(50, text.Rotation, map);
×
1303
                }
×
1304

1305
                if (text.ObliqueAngle != 0.0)
868!
1306
                {
×
1307
                        this._writer.Write(51, text.ObliqueAngle, map);
×
1308
                }
×
1309

1310
                this._writer.Write(7, text.Style.Name);
868✔
1311

1312
                this._writer.Write(11, text.AlignmentPoint, map);
868✔
1313

1314
                this._writer.Write(210, text.Normal, map);
868✔
1315

1316
                if (text.Mirror != 0)
868!
1317
                {
×
1318
                        this._writer.Write(71, text.Mirror, map);
×
1319
                }
×
1320
                if (text.HorizontalAlignment != 0)
868✔
1321
                {
36✔
1322
                        this._writer.Write(72, text.HorizontalAlignment, map);
36✔
1323
                }
36✔
1324

1325
                if (text.GetType() == typeof(TextEntity))
868✔
1326
                {
628✔
1327
                        this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Text);
628✔
1328

1329
                        if (text.VerticalAlignment != 0)
628✔
1330
                        {
6✔
1331
                                this._writer.Write(73, text.VerticalAlignment, map);
6✔
1332
                        }
6✔
1333
                }
628✔
1334

1335
                if (text is AttributeBase)
868✔
1336
                {
240✔
1337
                        switch (text)
240!
1338
                        {
1339
                                case AttributeEntity att:
1340
                                        this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Attribute);
116✔
1341
                                        this.writeAttributeBase(att);
116✔
1342
                                        break;
116✔
1343
                                case AttributeDefinition attdef:
1344
                                        this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.AttributeDefinition);
124✔
1345
                                        this._writer.Write(3, attdef.Prompt, DxfClassMap.Create<AttributeDefinition>());
124✔
1346
                                        this.writeAttributeBase(attdef);
124✔
1347
                                        break;
124✔
1348
                                default:
1349
                                        throw new ArgumentException($"Unknown AttributeBase type {text.GetType().FullName}");
×
1350
                        }
1351
                }
240✔
1352
        }
868✔
1353

1354
        private void writeTolerance(Tolerance tolerance)
1355
        {
60✔
1356
                DxfClassMap map = DxfClassMap.Create<Tolerance>();
60✔
1357

1358
                this._writer.Write(DxfCode.Subclass, tolerance.SubclassMarker);
60✔
1359

1360
                this._writer.WriteName(3, tolerance.Style, map);
60✔
1361

1362
                this._writer.Write(10, tolerance.InsertionPoint, map);
60✔
1363
                this._writer.Write(11, tolerance.Direction, map);
60✔
1364
                this._writer.Write(210, tolerance.Normal, map);
60✔
1365
                this._writer.Write(1, tolerance.Text, map);
60✔
1366
        }
60✔
1367

1368
        private void writeVertex(Vertex v)
1369
        {
2,682✔
1370
                DxfClassMap map = DxfClassMap.Create<Vertex>();
2,682✔
1371

1372
                if (v is not VertexFaceRecord)
2,682✔
1373
                {
2,642✔
1374
                        this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Vertex);
2,642✔
1375
                }
2,642✔
1376

1377
                this._writer.Write(DxfCode.Subclass, v.SubclassMarker);
2,682✔
1378

1379
                this._writer.Write(10, v.Location, map);
2,682✔
1380

1381
                this._writer.WriteIfNotDefault(40, v.StartWidth, 0, map);
2,682✔
1382
                this._writer.WriteIfNotDefault(41, v.EndWidth, 0, map);
2,682✔
1383
                this._writer.WriteIfNotDefault(42, v.Bulge, 0, map);
2,682✔
1384

1385
                this._writer.Write(70, v.Flags, map);
2,682✔
1386

1387
                this._writer.Write(50, v.CurveTangent, map);
2,682✔
1388

1389
                if (v is VertexFaceRecord faceRecord)
2,682✔
1390
                {
40✔
1391
                        this._writer.Write(71, faceRecord.Index1, map);
40✔
1392
                        this._writer.Write(72, faceRecord.Index2, map);
40✔
1393
                        this._writer.Write(73, faceRecord.Index3, map);
40✔
1394
                        this._writer.Write(74, faceRecord.Index4, map);
40✔
1395
                }
40✔
1396
        }
2,682✔
1397

1398
        private void writeViewport(Viewport vp)
1399
        {
571✔
1400
                DxfClassMap map = DxfClassMap.Create<Viewport>();
571✔
1401

1402
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Viewport);
571✔
1403

1404
                this._writer.Write(10, vp.Center, map);
571✔
1405

1406
                this._writer.Write(40, vp.Width, map);
571✔
1407
                this._writer.Write(41, vp.Height, map);
571✔
1408

1409
                this._writer.Write(68, vp.ActiveStatus, map);
571✔
1410
                this._writer.Write(69, vp.Id, map);
571✔
1411

1412
                this._writer.Write(12, vp.ViewCenter, map);
571✔
1413

1414
                this._writer.Write(13, vp.SnapBase, map);
571✔
1415

1416
                this._writer.Write(14, vp.SnapSpacing, map);
571✔
1417

1418
                this._writer.Write(15, vp.GridSpacing, map);
571✔
1419

1420
                this._writer.Write(16, vp.ViewDirection, map);
571✔
1421

1422
                this._writer.Write(17, vp.ViewTarget, map);
571✔
1423

1424
                this._writer.Write(42, vp.LensLength, map);
571✔
1425

1426
                this._writer.Write(43, vp.FrontClipPlane, map);
571✔
1427
                this._writer.Write(44, vp.BackClipPlane, map);
571✔
1428
                this._writer.Write(45, vp.ViewHeight, map);
571✔
1429

1430
                this._writer.Write(50, vp.SnapAngle, map);
571✔
1431
                this._writer.Write(51, vp.TwistAngle, map);
571✔
1432

1433
                this._writer.Write(72, vp.CircleZoomPercent, map);
571✔
1434

1435
                foreach (var layer in vp.FrozenLayers)
1,713!
1436
                {
×
1437
                        this._writer.Write(331, layer.Handle, map);
×
1438
                }
×
1439

1440
                this._writer.Write(90, (int)vp.Status, map);
571✔
1441

1442
                if (vp.Boundary != null)
571!
1443
                {
×
1444
                        this._writer.Write(340, vp.Boundary.Handle, map);
×
1445
                }
×
1446

1447
                this._writer.Write(110, vp.UcsOrigin, map);
571✔
1448

1449
                this._writer.Write(111, vp.UcsXAxis, map);
571✔
1450

1451
                this._writer.Write(112, vp.UcsYAxis, map);
571✔
1452
        }
571✔
1453

1454
        private void writeXLine(XLine xline)
1455
        {
20✔
1456
                DxfClassMap map = DxfClassMap.Create<XLine>();
20✔
1457

1458
                this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.XLine);
20✔
1459

1460
                this._writer.Write(10, xline.FirstPoint, map);
20✔
1461
                this._writer.Write(11, xline.Direction, map);
20✔
1462
        }
20✔
1463
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc