• 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/CadObject.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Objects;
3
using ACadSharp.Objects.Collections;
4
using ACadSharp.Tables;
5
using ACadSharp.Tables.Collections;
6
using ACadSharp.XData;
7
using System;
8
using ACadSharp.XData;
9
using System.Collections.Generic;
10
using System.Linq;
11

12
namespace ACadSharp
13
{
14
        /// <summary>
15
        /// Represents an element in a CadDocument
16
        /// </summary>
17
        public abstract class CadObject : IHandledCadObject
18
        {
19
                /// <summary>
20
                /// Get the object type
21
                /// </summary>
22
                public abstract ObjectType ObjectType { get; }
23

24
                /// <summary>
25
                /// The CAD class name of an object
26
                /// </summary>
27
                public virtual string ObjectName { get; }
×
28

29
                /// <summary>
30
                /// Object Subclass marker
31
                /// </summary>
32
                public abstract string SubclassMarker { get; }
33

34
                /// <inheritdoc/>
35
                /// <remarks>
36
                /// If the value is 0 the object is not assigned to a document or a parent
37
                /// </remarks>
38
                [DxfCodeValue(5)]
39
                public ulong Handle { get; internal set; }
×
40

41
                /// <summary>
42
                /// Soft-pointer ID/handle to owner object
43
                /// </summary>
44
                [DxfCodeValue(DxfReferenceType.Handle, 330)]
45
                public IHandledCadObject Owner { get; internal set; }
×
46

47
                /// <summary>
48
                /// Extended Dictionary object.
49
                /// </summary>
50
                /// <remarks>
51
                /// An extended dictionary can be created using <see cref="CreateExtendedDictionary"/>
52
                /// </remarks>
53
                public CadDictionary XDictionary
54
                {
55
                        get { return this._xdictionary; }
×
56
                        internal set
57
                        {
×
58
                                if (value == null)
×
59
                                        return;
×
60

61
                                this._xdictionary = value;
×
62
                                this._xdictionary.Owner = this;
×
63

64
                                if (this.Document != null)
×
65
                                        this.Document.RegisterCollection(this._xdictionary);
×
66
                        }
×
67
                }
68

69
                /// <summary>
70
                /// Objects that are attached to this object.
71
                /// </summary>
72
                /// <remarks>
73
                /// This collection is not managed by ACadSharp, any changes may cause a corruption in the file.
74
                /// </remarks>
75
                public Dictionary<ulong, CadObject> Reactors { get; } = new Dictionary<ulong, CadObject>();
×
76

77
                /// <summary>
78
                /// Extended data attached to this object.
79
                /// </summary>
80
                public ExtendedDataDictionary ExtendedData { get; }
×
81

82
                /// <summary>
83
                /// Document where this element belongs.
84
                /// </summary>
85
                public CadDocument Document
86
                {
87
                        get;
×
88
                        private set;
×
89
                }
90

91
                private CadDictionary _xdictionary = null;
×
92

93
                /// <summary>
94
                /// Default constructor.
95
                /// </summary>
96
                public CadObject()
×
97
                {
×
98
                        this.ExtendedData = new ExtendedDataDictionary(this);
×
99
                }
×
100

101
                /// <summary>
102
                /// Creates the extended dictionary if null.
103
                /// </summary>
104
                /// <returns>The <see cref="CadDictionary"/> attached to this <see cref="CadObject"/></returns>
105
                public CadDictionary CreateExtendedDictionary()
106
                {
×
107
                        if (this._xdictionary == null)
×
108
                        {
×
109
                                this.XDictionary = new CadDictionary();
×
110
                        }
×
111

112
                        return this._xdictionary;
×
113
                }
×
114

115
                /// <summary>
116
                /// Creates a new object that is a copy of the current instance.
117
                /// </summary>
118
                /// <remarks>
119
                /// The copy will be unattached from the document or any reference.
120
                /// </remarks>
121
                /// <returns>A new object that is a copy of this instance.</returns>
122
                public virtual CadObject Clone()
123
                {
×
124
                        CadObject clone = (CadObject)this.MemberwiseClone();
×
125

126
                        clone.Handle = 0;
×
127

128
                        clone.Document = null;
×
129
                        clone.Owner = null;
×
130

131
                        //Collections
132
                        clone.Reactors.Clear();
×
133
                        clone.XDictionary = new CadDictionary();
×
134
                        clone.ExtendedData.Clear();
×
135

136
                        return clone;
×
137
                }
×
138

139
                /// <inheritdoc/>
140
                public override string ToString()
141
                {
×
142
                        return $"{this.ObjectName}:{this.Handle}";
×
143
                }
×
144

145
                internal virtual void AssignDocument(CadDocument doc)
146
                {
×
147
                        this.Document = doc;
×
148

149
                        if (this.XDictionary != null)
×
150
                        {
×
151
                                doc.RegisterCollection(this.XDictionary);
×
152
                        }
×
153

154
                        if (this.ExtendedData.Any())
×
155
                        {
×
156
                                //Reset existing collection
157
                                var entries = this.ExtendedData.ToArray();
×
158
                                this.ExtendedData.Clear();
×
159

160
                                foreach (var item in entries)
×
161
                                {
×
162
                                        this.ExtendedData.Add(item.Key, item.Value);
×
163
                                }
×
164
                        }
×
165
                }
×
166

167
                internal virtual void UnassignDocument()
168
                {
×
169
                        if (this.XDictionary != null)
×
170
                                this.Document.UnregisterCollection(this.XDictionary);
×
171

172
                        this.Handle = 0;
×
173
                        this.Document = null;
×
174

175
                        if (this.ExtendedData.Any())
×
176
                        {
×
177
                                //Reset existing collection
178
                                var entries = this.ExtendedData.ToArray();
×
179
                                this.ExtendedData.Clear();
×
180

181
                                foreach (var item in entries)
×
182
                                {
×
183
                                        this.ExtendedData.Add(item.Key.Clone() as AppId, item.Value);
×
184
                                }
×
185
                        }
×
186
                }
×
187

188
                protected T updateTable<T>(T entry, Table<T> table)
189
                        where T : TableEntry
190
                {
×
191
                        if (table == null)
×
192
                        {
×
193
                                return entry;
×
194
                        }
195

196
                        if (table.TryGetValue(entry.Name, out T existing))
×
197
                        {
×
198
                                return existing;
×
199
                        }
200
                        else
201
                        {
×
202
                                table.Add(entry);
×
203
                                return entry;
×
204
                        }
205
                }
×
206

207
                protected T updateCollection<T>(T entry, ObjectDictionaryCollection<T> collection)
208
                        where T : NonGraphicalObject
209
                {
×
210
                        if (collection == null || entry == null)
×
211
                        {
×
212
                                return entry;
×
213
                        }
214

215
                        if (collection.TryGetValue(entry.Name, out T existing))
×
216
                        {
×
217
                                return existing;
×
218
                        }
219
                        else
220
                        {
×
221
                                collection.Add(entry);
×
222
                                return entry;
×
223
                        }
224
                }
×
225
        }
226
}
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