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

DomCR / ACadSharp / 16421664328

21 Jul 2025 03:47PM UTC coverage: 75.103% (+0.003%) from 75.1%
16421664328

Pull #559

github

web-flow
Merge 189dbb327 into b070875e7
Pull Request #559: Issue 557 dimension block

5982 of 8767 branches covered (68.23%)

Branch coverage included in aggregate %.

326 of 468 new or added lines in 19 files covered. (69.66%)

1 existing line in 1 file now uncovered.

23866 of 30976 relevant lines covered (77.05%)

79057.23 hits per line

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

40.68
/src/ACadSharp/IO/CadWriterBase.cs
1
using CSUtilities.Text;
2
using System.Text;
3
using System;
4
using System.IO;
5
using ACadSharp.Classes;
6
using System.Linq;
7
using ACadSharp.Entities;
8
using ACadSharp.Tables;
9

10
namespace ACadSharp.IO
11
{
12
        /// <summary>
13
        /// Base class for the CAD writers.
14
        /// </summary>
15
        public abstract class CadWriterBase<T> : ICadWriter
16
                where T : CadWriterConfiguration, new()
17
        {
18
                /// <inheritdoc/>
19
                public event NotificationEventHandler OnNotification;
20

21
                /// <summary>
22
                /// Configuration for the writer.
23
                /// </summary>
24
                public T Configuration { get; set; } = new T();
724✔
25

26
                protected CadDocument _document;
27

28
                protected Encoding _encoding;
29

30
                protected Stream _stream;
31

32
                protected CadWriterBase(Stream stream, CadDocument document)
75✔
33
                {
75✔
34
                        this._stream = stream;
75✔
35
                        this._document = document;
75✔
36
                }
75✔
37

38
                /// <inheritdoc/>
39
                public abstract void Dispose();
40

41
                /// <inheritdoc/>
42
                public virtual void Write()
43
                {
74✔
44
                        this._document.UpdateDxfClasses(this.Configuration.ResetDxfClasses);
74✔
45

46
                        if (this.Configuration.UpdateDimensionsInModel)
74!
NEW
47
                        {
×
NEW
48
                                this.updateDimensions(this._document.ModelSpace);
×
NEW
49
                        }
×
50

51
                        if (this.Configuration.UpdateDimensionsInBlocks)
74!
NEW
52
                        {
×
NEW
53
                                foreach (var item in this._document.BlockRecords)
×
NEW
54
                                {
×
NEW
55
                                        if (item.Name.Equals(BlockRecord.ModelSpaceName, StringComparison.OrdinalIgnoreCase))
×
NEW
56
                                        {
×
NEW
57
                                                continue;
×
58
                                        }
59

NEW
60
                                        this.updateDimensions(item);
×
NEW
61
                                }
×
NEW
62
                        }
×
63

64
                        this._encoding = this.getListedEncoding(this._document.Header.CodePage);
74✔
65
                }
74✔
66

67
                protected Encoding getListedEncoding(string codePage)
68
                {
74✔
69
                        CodePage code = CadUtils.GetCodePage(codePage);
74✔
70

71
                        try
72
                        {
74✔
73
#if !NET48
74
                                Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
74✔
75
#endif
76
                                return Encoding.GetEncoding((int)code);
74✔
77
                        }
78
                        catch (Exception ex)
×
79
                        {
×
80
                                this.triggerNotification($"Encoding with code {code} not found, using Windows-1252 as default", NotificationType.Warning, ex);
×
81
                        }
×
82

83
                        return TextEncoding.Windows1252();
×
84
                }
74✔
85

86
                protected void triggerNotification(string message, NotificationType notificationType, Exception ex = null)
87
                {
×
88
                        this.triggerNotification(this, new NotificationEventArgs(message, notificationType, ex));
×
89
                }
×
90

91
                protected void triggerNotification(object sender, NotificationEventArgs e)
92
                {
56✔
93
                        this.OnNotification?.Invoke(sender, e);
56!
94
                }
56✔
95

96
                private void updateDimensions(BlockRecord record)
NEW
97
                {
×
NEW
98
                        foreach (var item in record.Entities.OfType<Dimension>())
×
NEW
99
                        {
×
NEW
100
                                item.UpdateBlock();
×
NEW
101
                        }
×
NEW
102
                }
×
103
        }
104
}
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