• 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/Insert.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Tables;
3
using CSMath;
4
using System;
5
using System.Collections.Generic;
6
using System.Linq;
7

8
namespace ACadSharp.Entities
9
{
10
        /// <summary>
11
        /// Represents a <see cref="Insert"/> entity.
12
        /// </summary>
13
        /// <remarks>
14
        /// Object name <see cref="DxfFileToken.EntityInsert"/> <br/>
15
        /// Dxf class name <see cref="DxfSubclassMarker.Insert"/>
16
        /// </remarks>
17
        [DxfName(DxfFileToken.EntityInsert)]
18
        [DxfSubClass(DxfSubclassMarker.Insert)]
19
        public class Insert : Entity
20
        {
21
                /// <inheritdoc/>
22
                public override ObjectType ObjectType
23
                {
24
                        get
25
                        {
×
26
                                if (this.RowCount > 1 || this.ColumnCount > 1)
×
27
                                {
×
28
                                        return ObjectType.MINSERT;
×
29
                                }
30
                                else
31
                                {
×
32
                                        return ObjectType.INSERT;
×
33
                                }
34
                        }
×
35
                }
36

37
                /// <inheritdoc/>
38
                public override string ObjectName => DxfFileToken.EntityInsert;
×
39

40
                /// <inheritdoc/>
41
                public override string SubclassMarker => DxfSubclassMarker.Insert;
×
42

43
                /// <summary>
44
                /// Gets the insert block definition.
45
                /// </summary>
46
                [DxfCodeValue(DxfReferenceType.Name, 2)]
47
                public BlockRecord Block { get; internal set; }
×
48

49
                /// <summary>
50
                /// A 3D WCS coordinate representing the insertion or origin point.
51
                /// </summary>
52
                [DxfCodeValue(10, 20, 30)]
53
                public XYZ InsertPoint { get; set; } = XYZ.Zero;
×
54

55
                /// <summary>
56
                /// X scale factor.
57
                /// </summary>
58
                [DxfCodeValue(41)]
59
                public double XScale { get; set; } = 1;
×
60

61
                /// <summary>
62
                /// Y scale factor.
63
                /// </summary>
64
                [DxfCodeValue(42)]
65
                public double YScale { get; set; } = 1;
×
66

67
                /// <summary>
68
                /// Z scale factor.
69
                /// </summary>
70
                [DxfCodeValue(43)]
71
                public double ZScale { get; set; } = 1;
×
72

73
                /// <summary>
74
                /// Specifies the rotation angle for the object.
75
                /// </summary>
76
                /// <value>
77
                /// The rotation angle in radians.
78
                /// </value>
79
                [DxfCodeValue(DxfReferenceType.IsAngle, 50)]
80
                public double Rotation { get; set; } = 0.0;
×
81

82
                /// <summary>
83
                /// Specifies the three-dimensional normal unit vector for the object.
84
                /// </summary>
85
                [DxfCodeValue(210, 220, 230)]
86
                public XYZ Normal { get; set; } = XYZ.AxisZ;
×
87

88
                /// <summary>
89
                /// Column count
90
                /// </summary>
91
                [DxfCodeValue(DxfReferenceType.Optional, 70)]
92
                public ushort ColumnCount { get; set; } = 1;
×
93

94
                /// <summary>
95
                /// Row count
96
                /// </summary>
97
                [DxfCodeValue(DxfReferenceType.Optional, 71)]
98
                public ushort RowCount { get; set; } = 1;
×
99

100
                /// <summary>
101
                /// Column spacing
102
                /// </summary>
103
                [DxfCodeValue(DxfReferenceType.Optional, 44)]
104
                public double ColumnSpacing { get; set; } = 0;
×
105

106
                /// <summary>
107
                /// Row spacing
108
                /// </summary>
109
                [DxfCodeValue(DxfReferenceType.Optional, 45)]
110
                public double RowSpacing { get; set; } = 0;
×
111

112
                /// <summary>
113
                /// True if the insert has attribute entities in it
114
                /// </summary>
115
                [DxfCodeValue(DxfReferenceType.Ignored, 66)]
116
                public bool HasAttributes { get { return this.Attributes.Any(); } }
×
117

118
                /// <summary>
119
                /// Attributes from the block reference
120
                /// </summary>
121
                /// <remarks>
122
                /// If an attribute should be added in this collection a definition will be added into the block reference as well
123
                /// </remarks>
124
                public SeqendCollection<AttributeEntity> Attributes { get; private set; }
×
125

126
                internal Insert(bool onAdd = true) : base()
×
127
                {
×
128
                        this.Attributes = new SeqendCollection<AttributeEntity>(this);
×
129

130
                        if (onAdd)
×
131
                        {
×
132
                                this.Attributes.OnAdd += this.attributesOnAdd;
×
133
                        }
×
134
                }
×
135

136
                /// <summary>
137
                /// Constructor to reference an insert to a block record
138
                /// </summary>
139
                /// <param name="block">Block Record to reference</param>
140
                /// <exception cref="ArgumentNullException"></exception>
141
                public Insert(BlockRecord block) : this(false)
×
142
                {
×
143
                        if (block is null) throw new ArgumentNullException(nameof(block));
×
144

145
                        if (block.Document != null)
×
146
                        {
×
147
                                this.Block = (BlockRecord)block.Clone();
×
148
                        }
×
149
                        else
150
                        {
×
151
                                this.Block = block;
×
152
                        }
×
153

154
                        foreach (AttributeDefinition attdef in block.AttributeDefinitions)
×
155
                        {
×
156
                                this.Attributes.Add(new AttributeEntity(attdef));
×
157
                        }
×
158

159
                        this.Attributes.OnAdd += this.attributesOnAdd;
×
160
                }
×
161

162
                /// <summary>
163
                /// Updates all attribute definitions contained in the block reference as Attribute entitites in the insert
164
                /// </summary>
165
                /// <exception cref="NotImplementedException"></exception>
166
                public void UpdateAttributes()
167
                {
×
168
                        throw new NotImplementedException();
×
169
                }
170

171
                /// <inheritdoc/>
172
                public override BoundingBox GetBoundingBox()
173
                {
×
174
                        BoundingBox box = this.Block.BlockEntity.GetBoundingBox();
×
175

176
                        var scale = new XYZ(this.XScale, this.YScale, this.ZScale);
×
177
                        var min = box.Min * scale + this.InsertPoint;
×
178
                        var max = box.Max * scale + this.InsertPoint;
×
179

180
                        return new BoundingBox(min, max);
×
181
                }
×
182

183
                /// <inheritdoc/>
184
                public override CadObject Clone()
185
                {
×
186
                        Insert clone = (Insert)base.Clone();
×
187

188
                        clone.Block = (BlockRecord)this.Block?.Clone();
×
189

190
                        clone.Attributes = new SeqendCollection<AttributeEntity>(clone);
×
191
                        foreach (var att in this.Attributes)
×
192
                        {
×
193
                                clone.Attributes.Add((AttributeEntity)att.Clone());
×
194
                        }
×
195

196
                        return clone;
×
197
                }
×
198

199
                internal override void AssignDocument(CadDocument doc)
200
                {
×
201
                        base.AssignDocument(doc);
×
202

203
                        doc.RegisterCollection(this.Attributes);
×
204

205
                        //Should only be triggered for internal use
206
                        if (this.Block == null)
×
207
                                return;
×
208

209
                        if (doc.BlockRecords.TryGetValue(this.Block.Name, out BlockRecord blk))
×
210
                        {
×
211
                                this.Block = blk;
×
212
                        }
×
213
                        else
214
                        {
×
215
                                doc.BlockRecords.Add(this.Block);
×
216
                        }
×
217
                }
×
218

219
                internal override void UnassignDocument()
220
                {
×
221
                        this.Block = (BlockRecord)this.Block.Clone();
×
222
                        this.Document.UnregisterCollection(this.Attributes);
×
223

224
                        base.UnassignDocument();
×
225
                }
×
226

227
                private void attributesOnAdd(object sender, CollectionChangedEventArgs e)
228
                {
×
229
                        //TODO: Fix the relation between insert and block
230
                        //this.Block?.Entities.Add(new AttributeDefinition(e.Item as AttributeEntity));
231
                }
×
232
        }
233
}
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