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

DomCR / ACadSharp / 13817713986

12 Mar 2025 05:27PM UTC coverage: 76.2% (-0.01%) from 76.21%
13817713986

push

github

web-flow
Merge pull request #576 from DomCR/issue-575_write-group

Write Group

5490 of 7909 branches covered (69.41%)

Branch coverage included in aggregate %.

66 of 106 new or added lines in 8 files covered. (62.26%)

3 existing lines in 2 files now uncovered.

21657 of 27717 relevant lines covered (78.14%)

75614.07 hits per line

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

62.5
/src/ACadSharp/Objects/Group.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Entities;
3
using ACadSharp.Objects.Collections;
4
using CSUtilities.Extensions;
5
using System.Collections.Generic;
6

7
namespace ACadSharp.Objects
8
{
9
        /// <summary>
10
        /// Represents a <see cref="Group"/> object.
11
        /// </summary>
12
        /// <remarks>
13
        /// Object name <see cref="DxfFileToken.TableGroup"/> <br/>
14
        /// Dxf class name <see cref="DxfSubclassMarker.Group"/>
15
        /// </remarks>
16
        [DxfName(DxfFileToken.TableGroup)]
17
        [DxfSubClass(DxfSubclassMarker.Group)]
18
        public class Group : NonGraphicalObject
19
        {
20
                /// <summary>
21
                /// Group description.
22
                /// </summary>
23
                [DxfCodeValue(300)]
24
                public string Description { get; set; } = string.Empty;
1,304✔
25

26
                /// <summary>
27
                /// Entities in this group.
28
                /// </summary>
29
                /// <remarks>
30
                /// Hard-pointer handle to entity in group.
31
                /// </remarks>
32
                [DxfCollectionCodeValue(DxfReferenceType.Handle, 340)]
33
                public IEnumerable<Entity> Entities { get { return this._entities; } }
9✔
34

35
                /// <summary>
36
                /// If the group has an automatic generated name.
37
                /// </summary>
38
                /// <remarks>
39
                /// The name for an unnamed group will be managed by the <see cref="GroupCollection"/>.
40
                /// </remarks>
41
                [DxfCodeValue(70)]
42
                public bool IsUnnamed { get { return this.Name.IsNullOrWhiteSpace() || this.Name.StartsWith("*"); } }
15✔
43

44
                /// <inheritdoc/>
45
                public override string ObjectName => DxfFileToken.TableGroup;
×
46

47
                /// <inheritdoc/>
NEW
48
                public override ObjectType ObjectType => ObjectType.GROUP;
×
49

50
                /// <summary>
51
                /// If the group is selectable.
52
                /// </summary>
53
                [DxfCodeValue(71)]
54
                public bool Selectable { get; set; } = true;
1,305✔
55

56
                /// <inheritdoc/>
57
                public override string SubclassMarker => DxfSubclassMarker.Group;
2,304✔
58

59
                private List<Entity> _entities = new();
654✔
60

61
                /// <inheritdoc/>
62
                public Group() : base()
653✔
63
                {
653✔
64
                }
653✔
65

66
                /// <inheritdoc/>
67
                public Group(string name) : base(name)
1✔
68
                {
1✔
69
                }
1✔
70

71
                /// <summary>
72
                /// Add an entity to the group.
73
                /// </summary>
74
                /// <param name="entity"></param>
75
                public void Add(Entity entity)
76
                {
3,903✔
77
                        if (this.Document != entity.Document)
3,903✔
78
                        {
1✔
79
                                throw new System.InvalidOperationException("The Group and the entity must belong to the same document.");
1✔
80
                        }
81

82
                        this._entities.Add(entity);
3,902✔
83
                        entity.AddReactor(this);
3,902✔
84
                }
3,902✔
85

86
                /// <summary>
87
                /// Add multiple entities into the group.
88
                /// </summary>
89
                /// <param name="entities"></param>
90
                public void AddRange(IEnumerable<Entity> entities)
NEW
91
                {
×
NEW
92
                        foreach (var e in entities)
×
NEW
93
                        {
×
NEW
94
                                this.Add(e);
×
NEW
95
                        }
×
NEW
96
                }
×
97

98
                /// <summary>
99
                /// Removes all entities in the group.
100
                /// </summary>
101
                public void Clear()
102
                {
1✔
103
                        foreach (var e in this._entities)
5✔
104
                        {
1✔
105
                                e.RemoveReactor(this);
1✔
106
                        }
1✔
107

108
                        this._entities.Clear();
1✔
109
                }
1✔
110

111
                /// <summary>
112
                /// Removes the entity from the group.
113
                /// </summary>
114
                /// <param name="entity"></param>
115
                public bool Remove(Entity entity)
NEW
116
                {
×
NEW
117
                        entity.RemoveReactor(this);
×
NEW
118
                        return this._entities.Remove(entity);
×
NEW
119
                }
×
120

121
                /// <inheritdoc/>
122
                public override CadObject Clone()
123
                {
1✔
124
                        Group clone = (Group)base.Clone();
1✔
125

126
                        clone._entities = new();
1✔
127

128
                        return clone;
1✔
129
                }
1✔
130

131
                internal override void AssignDocument(CadDocument doc)
132
                {
651✔
133
                        base.AssignDocument(doc);
651✔
134
                }
651✔
135

136
                internal override void UnassignDocument()
NEW
137
                {
×
NEW
138
                        base.UnassignDocument();
×
139

NEW
140
                        foreach (var e in this._entities)
×
NEW
141
                        {
×
NEW
142
                                e.RemoveReactor(this);
×
NEW
143
                        }
×
144

NEW
145
                        this._entities.Clear();
×
NEW
146
                }
×
147
        }
148
}
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