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

DomCR / ACadSharp / 12905761471

22 Jan 2025 10:03AM UTC coverage: 2.0% (-74.0%) from 75.963%
12905761471

push

github

DomCR
version 1.0.6

104 of 7676 branches covered (1.35%)

Branch coverage included in aggregate %.

590 of 27024 relevant lines covered (2.18%)

5.13 hits per line

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

0.0
/src/ACadSharp/Entities/CadImageBase.cs
1
using ACadSharp.Attributes;
2
using CSMath;
3
using System.Collections.Generic;
4
using System;
5
using ACadSharp.Objects;
6
using System.Linq;
7

8
namespace ACadSharp.Entities
9
{
10
        /// <summary>
11
        /// Common base class for <see cref="RasterImage" /> and <see cref="Wipeout" />.
12
        /// </summary>
13
        [DxfSubClass(null, true)]
14
        public abstract class CadImageBase : Entity
15
        {
16
                /// <summary>
17
                /// Class version
18
                /// </summary>
19
                [DxfCodeValue(90)]
20
                public int ClassVersion { get; set; }
×
21

22
                /// <summary>
23
                /// Insertion point(in WCS)
24
                /// </summary>
25
                [DxfCodeValue(10, 20, 30)]
26
                public XYZ InsertPoint { get; set; }
×
27

28
                /// <summary>
29
                /// U-vector of a single pixel(points along the visual bottom of the image, starting at the insertion point) (in WCS)
30
                /// </summary>
31
                [DxfCodeValue(11, 21, 31)]
32
                public XYZ UVector { get; set; } = XYZ.AxisX;
×
33

34
                /// <summary>
35
                /// V-vector of a single pixel(points along the visual left side of the image, starting at the insertion point) (in WCS)
36
                /// </summary>
37
                [DxfCodeValue(12, 22, 32)]
38
                public XYZ VVector { get; set; } = XYZ.AxisY;
×
39

40
                /// <summary>
41
                /// Image size in pixels
42
                /// </summary>
43
                /// <remarks>
44
                /// 2D point(U and V values)
45
                /// </remarks>
46
                [DxfCodeValue(13, 23)]
47
                public XY Size { get; set; }
×
48

49
                /// <summary>
50
                /// Image display properties
51
                /// </summary>
52
                [DxfCodeValue(70)]
53
                public ImageDisplayFlags Flags { get; set; }
×
54

55
                /// <summary>
56
                /// Clipping state
57
                /// </summary>
58
                [DxfCodeValue(280)]
59
                public bool ClippingState { get; set; }
×
60

61
                /// <summary>
62
                /// Brightness
63
                /// </summary>
64
                /// <remarks>
65
                /// 0-100; default = 50
66
                /// </remarks>
67
                [DxfCodeValue(281)]
68
                public byte Brightness
69
                {
70
                        get { return this._brightness; }
×
71
                        set
72
                        {
×
73
                                if (value < 0 || value > 100)
×
74
                                {
×
75
                                        throw new ArgumentException($"Invalid Brightness value: {value}, must be in range 0-100");
×
76
                                }
77

78
                                this._brightness = value;
×
79
                        }
×
80
                }
81

82
                /// <summary>
83
                /// Contrast
84
                /// </summary>
85
                /// <remarks>
86
                /// 0-100; default = 50
87
                /// </remarks>
88
                [DxfCodeValue(282)]
89
                public byte Contrast
90
                {
91
                        get { return this._contrast; }
×
92
                        set
93
                        {
×
94
                                if (value < 0 || value > 100)
×
95
                                {
×
96
                                        throw new ArgumentException($"Invalid Brightness value: {value}, must be in range 0-100");
×
97
                                }
98

99
                                this._contrast = value;
×
100
                        }
×
101
                }
102

103
                /// <summary>
104
                /// Fade
105
                /// </summary>
106
                /// <remarks>
107
                /// 0-100; default = 0
108
                /// </remarks>
109
                [DxfCodeValue(283)]
110
                public byte Fade
111
                {
112
                        get { return this._fade; }
×
113
                        set
114
                        {
×
115
                                if (value < 0 || value > 100)
×
116
                                {
×
117
                                        throw new ArgumentException($"Invalid Brightness value: {value}, must be in range 0-100");
×
118
                                }
119

120
                                this._fade = value;
×
121
                        }
×
122
                }
123

124
                /// <summary>
125
                /// Clipping state
126
                /// </summary>
127
                [DxfCodeValue(290)]
128
                public ClipMode ClipMode { get; set; }
×
129

130
                /// <summary>
131
                /// Clipping boundary type
132
                /// </summary>
133
                [DxfCodeValue(71)]
134
                public ClipType ClipType { get; set; } = ClipType.Rectangular;
×
135

136
                /// <summary>
137
                /// Clip boundary vertices
138
                /// </summary>
139
                /// <remarks>
140
                /// For rectangular clip boundary type, two opposite corners must be specified.Default is (-0.5,-0.5), (size.x-0.5, size.y-0.5). 2) For polygonal clip boundary type, three or more vertices must be specified.Polygonal vertices must be listed sequentially
141
                /// </remarks>
142
                [DxfCodeValue(DxfReferenceType.Count, 91)]
143
                [DxfCollectionCodeValue(14, 24)]
144
                public List<XY> ClipBoundaryVertices { get; set; } = new List<XY>();
×
145

146
                /// <summary>
147
                /// Image definition.
148
                /// </summary>
149
                [DxfCodeValue(DxfReferenceType.Handle, 340)]
150
                public ImageDefinition Definition
151
                {
152
                        get { return this._definition; }
×
153
                        set
154
                        {
×
155
                                if (value == null)
×
156
                                {
×
157
                                        return;
×
158
                                }
159

160
                                if (this.Document != null)
×
161
                                {
×
162
                                        this._definition = this.updateCollection(value, this.Document.ImageDefinitions);
×
163
                                }
×
164
                                else
165
                                {
×
166
                                        this._definition = value;
×
167
                                }
×
168
                        }
×
169
                }
170

171
                /// <summary>
172
                /// Reference to image definition reactor
173
                /// </summary>
174
                //It seems that is not necessecary, keep it hidden for now
175
                [DxfCodeValue(DxfReferenceType.Handle, 360)]
176
                internal ImageDefinitionReactor DefinitionReactor
177
                {
178
                        get { return this._definitionReactor; }
×
179
                        set
180
                        {
×
181
                                this._definitionReactor = value;
×
182
                        }
×
183
                }
184

185
                private byte _brightness = 50;
×
186
                private byte _contrast = 50;
×
187
                private byte _fade = 0;
×
188

189
                private ImageDefinition _definition;
190
                private ImageDefinitionReactor _definitionReactor;
191

192
                /// <inheritdoc/>
193
                public override BoundingBox GetBoundingBox()
194
                {
×
195
                        if (!this.ClipBoundaryVertices.Any())
×
196
                        {
×
197
                                return BoundingBox.Null;
×
198
                        }
199

200
                        double minX = this.ClipBoundaryVertices.Select(v => v.X).Min();
×
201
                        double minY = this.ClipBoundaryVertices.Select(v => v.Y).Min();
×
202
                        XYZ min = new XYZ(minX, minY, 0) + this.InsertPoint;
×
203

204
                        double maxX = this.ClipBoundaryVertices.Select(v => v.X).Max();
×
205
                        double maxY = this.ClipBoundaryVertices.Select(v => v.Y).Max();
×
206
                        XYZ max = new XYZ(maxX, maxY, 0) + this.InsertPoint;
×
207

208
                        BoundingBox box = new BoundingBox(min, max);
×
209

210
                        return box;
×
211
                }
×
212

213
                /// <inheritdoc/>
214
                public override CadObject Clone()
215
                {
×
216
                        CadImageBase clone = (CadImageBase)base.Clone();
×
217

218
                        clone.Definition = (ImageDefinition)this.Definition?.Clone();
×
219

220
                        return clone;
×
221
                }
×
222

223
                internal override void AssignDocument(CadDocument doc)
224
                {
×
225
                        base.AssignDocument(doc);
×
226

227
                        this._definition = this.updateCollection(this.Definition, doc.ImageDefinitions);
×
228

229
                        this.Document.ImageDefinitions.OnRemove += this.imageDefinitionsOnRemove;
×
230
                }
×
231

232
                internal override void UnassignDocument()
233
                {
×
234
                        this.Document.ImageDefinitions.OnRemove -= this.imageDefinitionsOnRemove;
×
235

236
                        base.UnassignDocument();
×
237

238
                        this.Definition = (ImageDefinition)this.Definition?.Clone();
×
239
                }
×
240

241
                private void imageDefinitionsOnRemove(object sender, CollectionChangedEventArgs e)
242
                {
×
243
                        if (e.Item.Equals(this.Definition))
×
244
                        {
×
245
                                this.Definition = null;
×
246
                        }
×
247
                }
×
248
        }
249
}
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