File tree Expand file tree Collapse file tree 5 files changed +90
-9
lines changed Expand file tree Collapse file tree 5 files changed +90
-9
lines changed Original file line number Diff line number Diff line change
1
+ using ACadSharp . Entities ;
2
+ using ACadSharp . Objects ;
3
+ using System ;
4
+ using Xunit ;
5
+
6
+ namespace ACadSharp . Tests . Objects
7
+ {
8
+ public class GroupTests : NonGraphicalObjectTests < Group >
9
+ {
10
+ [ Fact ]
11
+ public void AddTest ( )
12
+ {
13
+ CadDocument doc = new CadDocument ( ) ;
14
+ Line l = new Line ( ) ;
15
+ var group = new Group ( ) ;
16
+
17
+ group . Add ( l ) ;
18
+
19
+ Assert . Contains ( group , l . Reactors ) ;
20
+ Assert . Throws < InvalidOperationException > ( ( ) => doc . Groups . Add ( group ) ) ;
21
+
22
+ group . Clear ( ) ;
23
+
24
+ Assert . DoesNotContain ( group , l . Reactors ) ;
25
+
26
+ doc . Groups . Add ( group ) ;
27
+ Assert . Contains ( group , doc . Groups ) ;
28
+
29
+ Assert . Throws < InvalidOperationException > ( ( ) => group . Add ( l ) ) ;
30
+
31
+ doc . Entities . Add ( l ) ;
32
+ group . Add ( l ) ;
33
+
34
+ Assert . Contains ( l , group . Entities ) ;
35
+ }
36
+
37
+ [ Fact ]
38
+ public void IsUnnamedTest ( )
39
+ {
40
+ var group = new Group ( ) ;
41
+
42
+ Assert . True ( group . IsUnnamed ) ;
43
+ group . Name = null ;
44
+ Assert . True ( group . IsUnnamed ) ;
45
+ group . Name = " " ;
46
+ Assert . True ( group . IsUnnamed ) ;
47
+
48
+ group . Name = "my_group" ;
49
+ Assert . False ( group . IsUnnamed ) ;
50
+ }
51
+ }
52
+ }
Original file line number Diff line number Diff line change @@ -59,14 +59,7 @@ public IEnumerable<CadObject> Reactors
59
59
{
60
60
get
61
61
{
62
- if ( this . Document == null )
63
- {
64
- return Enumerable . Empty < CadObject > ( ) ;
65
- }
66
- else
67
- {
68
- return this . _reactors ;
69
- }
62
+ return this . _reactors ;
70
63
}
71
64
}
72
65
Original file line number Diff line number Diff line change 1
1
using ACadSharp . Entities ;
2
+ using System ;
2
3
using System . Collections . Generic ;
3
4
using System . Linq ;
4
5
using System . Text . RegularExpressions ;
@@ -15,6 +16,14 @@ public GroupCollection(CadDictionary dictionary) : base(dictionary)
15
16
/// <inheritdoc/>
16
17
public override void Add ( Group entry )
17
18
{
19
+ foreach ( var e in entry . Entities )
20
+ {
21
+ if ( e . Document != this . _dictionary . Document )
22
+ {
23
+ throw new InvalidOperationException ( "Entities in a group must be in the same document as the group being added." ) ;
24
+ }
25
+ }
26
+
18
27
if ( entry . IsUnnamed )
19
28
{
20
29
int next = 0 ;
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ public class Group : NonGraphicalObject
39
39
/// The name for an unnamed group will be managed by the <see cref="GroupCollection"/>.
40
40
/// </remarks>
41
41
[ DxfCodeValue ( 70 ) ]
42
- public bool IsUnnamed { get { return ! this . Name . IsNullOrWhiteSpace ( ) && this . Name . StartsWith ( "*" ) ; } }
42
+ public bool IsUnnamed { get { return this . Name . IsNullOrWhiteSpace ( ) || this . Name . StartsWith ( "*" ) ; } }
43
43
44
44
/// <inheritdoc/>
45
45
public override string ObjectName => DxfFileToken . TableGroup ;
@@ -95,6 +95,29 @@ public void AddRange(IEnumerable<Entity> entities)
95
95
}
96
96
}
97
97
98
+ /// <summary>
99
+ /// Removes all entities in the group.
100
+ /// </summary>
101
+ public void Clear ( )
102
+ {
103
+ foreach ( var e in this . _entities )
104
+ {
105
+ e . RemoveReactor ( this ) ;
106
+ }
107
+
108
+ this . _entities . Clear ( ) ;
109
+ }
110
+
111
+ /// <summary>
112
+ /// Removes the entity from the group.
113
+ /// </summary>
114
+ /// <param name="entity"></param>
115
+ public bool Remove ( Entity entity )
116
+ {
117
+ entity . RemoveReactor ( this ) ;
118
+ return this . _entities . Remove ( entity ) ;
119
+ }
120
+
98
121
/// <inheritdoc/>
99
122
public override CadObject Clone ( )
100
123
{
Original file line number Diff line number Diff line change 82
82
<value >False</value >
83
83
</setting >
84
84
<setting name =" Cleaning_InsertExplicitAccessModifiersOnProperties"
85
+ serializeAs =" String" >
86
+ <value >False</value >
87
+ </setting >
88
+ <setting name =" Cleaning_InsertBlankSpaceBeforeSelfClosingAngleBrackets"
85
89
serializeAs =" String" >
86
90
<value >True</value >
87
91
</setting >
You can’t perform that action at this time.
0 commit comments